Reputation: 6086
I'm trying to create my first HelloWorld servlet with Eclipse Juno and view it in 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 select "Run on Server" > "J2EE Preview" I get this:
Error 404 - Not Found
No context on this server matched or handled this request. Contexts known to this server are:
HelloWorld(/HelloWorld)
Where am I doing wrong?
Upvotes: 7
Views: 10061
Reputation: 1675
I had the same issue, and couldn't make it work. I created a much simplier application, just a hello world JSP page.
This process is very basic, you create a web dynamic project and create a index.jsp file under the WebContent directory, this should be good enough to start your application by run as -> run in server -> J2EE preview but always get:
404 not found No context on this server matched or handled this request. Contexts known to this server are: test(/test)
I have heard eclipse juno is not as stable as indigo, i just downloaded the indigo Java EE version did exacly the same and it worked properly no issues.
Edit: I Forgot to mention that you can download another Application Server such as JBoss or Glassfish and try to run on your application on them, that should fix your problem.
You can try to fix this issue by deleting all the files and folders into your workspace, delete the .metadata folder and all the content of it, the start eclipse and try again this may works.
Hope this can help you. Regards!
Upvotes: 0
Reputation: 4179
In "J2EE Preview" Server, context path is the name of the project. When you start the server, this list all contextpaths available.
For example, if your applications is named "app1", your URL will be "http://localhost:8080/app1/HelloWorld"
Upvotes: 1