This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error in simple servlet

 
Rasika Gopalakrishnan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1604
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Rasika Gopalakrishnan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1604
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use code tags to post your code. Does Ch1Servlet.class file under WEB-INF\classes folder?
 
Prasad Krishnegowda
Ranch Hand
Posts: 667
4
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic