aspose file tools*
The moose likes Servlets and the fly likes error while running the 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 while running the servlet" Watch "error while running the servlet" New topic
Author

error while running the servlet

melina ser
Greenhorn

Joined: Aug 27, 2006
Posts: 11
Hello all,

i am new to servlets programming.. and i have made a simple servlet program to print "hello world".

My Program is ->

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class First extends HttpServlet {

public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException,IOException {

PrintWriter out=response.getWriter();
out.println("hello world.this is my first Servlet");
}
}


i am using tomcat 4.1.31 and jdk1.4 versions.

the problem is i sucessfully get my program compiled in command prompt but when i run it ,it gives following error and doesnt get deployed :-

Exception in thread "main" java.lang.NoClassDefFoundError :First

can somebody tell me the cause of this problem and i dont think i have any error in the environment variables ,they are all set right.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Where did you put the First.class file?
Did you set up a servlet entry and a servlet-mapping in your web.xml file?
If so, please post them so we can see them.
What URL are you using when making a request to this servlet?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
melina ser
Greenhorn

Joined: Aug 27, 2006
Posts: 11
now when i m starting my tomcat server its giving some error...but when i run http://localhost:8080/ its working.....


now my web.xml file is like dis->

<?xml version="1.0"?>
<web-app>
<servlet>
<servlet-name> servlet1</servlet-name>
<servlet-class> HelloServlet </servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> servlet1</servlet-name>
<url-pattern>/se </url-pattern>
</servlet-mapping>
</web-app>

and i put my class file obtained after compiling program under this address

C:\Tomcat\webapps\GRE\WEB-INF\classes

[ September 07, 2006: Message edited by: melina ser ]
[ September 07, 2006: Message edited by: melina ser ]
melina ser
Greenhorn

Joined: Aug 27, 2006
Posts: 11
now i deploy the application ..that is the servlet in the browser ..with this address..->

http://localhost:8080/GRE/se

where se is alias name...

and i am getting an error like this...

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Wrapper cannot find servlet class HelloServlet or a class it depends on
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:844)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:621)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:163)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:144)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2358)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:133)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:118)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:116)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:127)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:152)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:536)

root cause

java.lang.ClassNotFoundException: HelloServlet
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1407)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1252)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:838)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:621)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:163)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:144)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2358)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:133)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:118)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:116)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:127)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:152)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:536)

Apache Tomcat/4.1.31
[ September 07, 2006: Message edited by: melina ser ]
melina ser
Greenhorn

Joined: Aug 27, 2006
Posts: 11
now where the error lies..can somebody tell ...
please help me because i have just started learning servlets and have nbo idea as to what should be done...
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12805
    
    5

That puts the HelloServlet class in the "default" package - JVMs try to load default package classes from the "current" directory. You have not control over this in the servlet environment.
THEREFORE: All classes used in servlets should be in a defined package and your configuration must reflect that.

The location of the class file must agree with the declared package.

Bill
[ September 07, 2006: Message edited by: William Brogden ]
melina ser
Greenhorn

Joined: Aug 27, 2006
Posts: 11
thanks a lot william.i changed my servlet claas part in the web.xml file and it worked .
So problem solved.
cheers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: error while running the servlet