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:
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.