0

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:

  1. Stop Tomcat.
  2. New Dynamic webproject.
  3. Call the project TestProject
  4. Use default options: Context = "TestProject", Context Directory = "WebContent", Java Source Directory = "src"
  5. Right click on project and select new servlet
  6. Use default package and call the class "HelloTest" all other options are defult
  7. 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.

2
  • Have you tried putting your servlet in a package instead of the default package? Also, how is your servlet mapped on the web.xml file? Commented Apr 23, 2009 at 12:14
  • 1
    Poject was not set to build automatically. Menu>Project>Build Automatically. Commented Apr 23, 2009 at 12:15

1 Answer 1

2

First check if the class is correcty deployed. See also this question.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.