aspose file tools*
The moose likes Servlets and the fly likes Error in simple servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Error in simple servlet" Watch "Error in simple servlet" New topic
Author

Error in simple servlet

Rasika Gopalakrishnan
Greenhorn

Joined: Dec 07, 2012
Posts: 7
I have written and deployed a simple servlet to display the current date. I am getting the following exception...

exception

javax.servlet.ServletException: Wrapper cannot find servlet class Ch1Servlet or a class it depends on
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:825)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:738)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:526)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
java.lang.Thread.run(Thread.java:619)


root cause

java.lang.ClassNotFoundException: Ch1Servlet
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1332)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1181)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:825)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:738)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:526)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
java.lang.Thread.run(Thread.java:619)

please help.
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

Rasika,

The class loader is failing to load your class. Could you please show us the source java file and deployment descriptor file(web.xml).


Swastik
Rasika Gopalakrishnan
Greenhorn

Joined: Dec 07, 2012
Posts: 7
Source file:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class Ch1Servlet extends HttpServlet
{
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
java.util.Date today=new java.util.Date();
out.println("<html> "+"<body>"+"<h1 align=center> HF\'s Chapter1 Servlet</h1>"+"<br>"+today+"</body>"+"</html>");
}
}


deployment descriptor:

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">

<servlet>
<servlet-name>Chapter1 Servlet</servlet-name>
<servlet-class>Ch1Servlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Chapter1 Servlet</servlet-name>
<url-pattern>/Serv1</url-pattern>
</servlet-mapping>

</web-app>
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

Use code tags to post your code. Does Ch1Servlet.class file under WEB-INF\classes folder?
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 537

Its always advised to put your classes in a package. Sometimes, tomcat has problems, with servlets(java classes) which are not inside a package...
Rasika Gopalakrishnan
Greenhorn

Joined: Dec 07, 2012
Posts: 7
Swastik Dey wrote:Use code tags to post your code. Does Ch1Servlet.class file under WEB-INF\classes folder?

Thank you Swastik Dey. I had the directory structure wrong.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error in simple servlet