Simple Servlet with Eclipse Juno Server and J2EE Preview

I am trying to create my first HelloWorld servlet with Eclipse Juno and view it on the J2EE preview server.

This is my servlet class:

import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * Servlet implementation class HelloWorld */ public class HelloWorld extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public HelloWorld() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter pw = response.getWriter(); pw.println("<html>"); pw.println("<head><title>Hello World</title></title>"); pw.println("<body>"); pw.println("<h1>Hello World</h1>"); pw.println("</body></html>"); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub } } 

And this is my web.xml automatically generated by eclipse:

 <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>HelloWorld</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <servlet> <description></description> <display-name>HelloWorld</display-name> <servlet-name>HelloWorld</servlet-name> <servlet-class>HelloWorld</servlet-class> </servlet> <servlet-mapping> <servlet-name>HelloWorld</servlet-name> <url-pattern>/HelloWorld</url-pattern> </servlet-mapping> </web-app> 

When I choose Run on Server> J2EE Preview, I get the following:

Error 404 - Not Found

No context on this server matches or processes this request. Contexts known to this server:

HelloWorld (/ HelloWorld)

Where am I doing wrong?

+7
source share
2 answers

In the "J2EE Preview" window, the server path is the name of the project. When you start the server, all available context paths are available in this list.

For example, if your applications are called "app1", your URL would be "http: // localhost: 8080 / app1 / HelloWorld"

+1
source

I had the same problem and I could not get it to work. I created a much simpler application, just a welcome JSP page.

This process is very simple, you create a web dynamic project and create an index.jsp file in the WebContent directory, this should be good enough to launch your application by doing as โ†’ run in server โ†’ J2EE preview, but always get:

404 not found No context on this server matched or processed this request. Contexts known to this server: test (/ test)

I heard that eclipse juno is not as stable as indigo, I just downloaded the Java EE version for indigo and it didn't work.

Edit: I forgot to mention that you can download another application server, such as JBoss or Glassfish, and try to run the application on them, which should fix your problem.

You can fix this problem by deleting all the files and folders in the workspace, delete the .metadata folder and all its contents, eclipse the launch and try again, this may work.

Hope this can help you. Hello!

0
source

All Articles