简体   繁体   中英

404 on GET request to Servlet

I have been trying for 3 days now to create a Java EE project, that uses JSP, Servlet and EJB in a single project, as I need to do a course final assignment on this.

We were instructed to use JBOSS 4.2.3, and so that is what I try to use.

I set up my environment as follows:

  1. http://community.linuxmint.com/tutorial/view/1372
  2. Install IntelliJ Idea 13 Ultimate.
  3. Download JBOSS and prepare a directory to use.
  4. After those 3 days of hard work, I managed to get a sample app, created by this tutorial: http://wiki.jetbrains.net/intellij/Developing_and_running_a_Java_EE_Hello_World_application#The_Hello_World_Java_EE_application

Now, the application compiles, I get the index.jsp on: http://localhost:8080/webWeb/

However, I get a 404 error if I click it, and submit to http://localhost:8080/webWeb/helloworld

I dont know what else to try, I think I Googled and read pretty much everything :( Here is a link to the Project archive, so that you could (potentially) test out my project, see if you can solve this problem somehow...

https://www.dropbox.com/sh/9sma5vh7usy2h3p/AADA64KPyLH29iGz8OamWyNna

Thanks!


UPDATE: For convenience, my HelloWorldServlet.java code:

package myservlets;

import mybeans.HelloWorldBean;

import javax.ejb.EJB;
import java.io.IOException;

@javax.servlet.annotation.WebServlet(name = "HelloWorldServlet", urlPatterns = "/helloworld")
public class HelloWorldServlet extends javax.servlet.http.HttpServlet {
    @EJB
    private HelloWorldBean helloWorldBean;
    protected void doPost(javax.servlet.http.HttpServletRequest request,
                          javax.servlet.http.HttpServletResponse response)
            throws javax.servlet.ServletException, IOException {

    }
    @Override
    protected void doGet(javax.servlet.http.HttpServletRequest request,
                         javax.servlet.http.HttpServletResponse response)
            throws javax.servlet.ServletException, IOException {
        String hello=helloWorldBean.sayHello();
        request.setAttribute("hello",hello);
        request.getRequestDispatcher("hello.jsp").forward(request,response);
    }
}

I feel I really must add, that this extreme difficulty of setting up Java to just work and allow me to focus on CODING , is the reason I prefer something like PHP, which just works for example... Am I wrong?

The problem is that you're using JBoss 4.2.3 which works with Servlet 2.5 / JSP 2.1 (as noted by BalusC here: Servlet Spec for Jboss 4.2.3 ). Usage of @WebServlet and annotations is supported since Servlet 3.0. So, you have to configure your servlets directly in web.xml file.

Note that servet 2.5 doesn't support EJB injection either.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM