I'm seeing a problem while attempting to run a java servlet under eclipse (Ganymede), I'm running Java 1.6 and Apache Tomcat 6.0.
Here is what i am doing:
- Stop Tomcat.
- New Dynamic webproject.
- Call the project TestProject
- Use default options: Context = "TestProject", Context Directory = "WebContent", Java Source Directory = "src"
- Right click on project and select new servlet
- Use default package and call the class "HelloTest" all other options are defult
- Change URL Mapping to /hello
The Code for the servlet is as follows (I've only edited the doGet and doPost methods everything else is generated):
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 HelloTest
*/
public class HelloTest extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public HelloTest() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter writer = response.getWriter();
writer.write("Hello World");
writer.flush();
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request,response);
}
}
Here is how I try to run the project: 1. Save the project 2. Right click on the project and select run on server. 3. Select existing Tomcat server 4. Click Finish.
When I try to browse to http://localhost:8080/TestProject/hello I get an exception saying that the class was not found.
javax.servlet.ServletException: Wrapper cannot find servlet class HelloTest or a class it depends on
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
java.lang.Thread.run(Thread.java:619)
root cause
java.lang.ClassNotFoundException: HelloTest
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
Am I doing something wrong?
If I add a .jsp page called test.jsp it displays perfectly, so I know Tomcat is running and serving pages and that I have the right path.