wood burning stoves 2.0*
The moose likes Servlets and the fly likes Error while accessing servlets from jsp in Tomcat? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Error while accessing servlets from jsp in Tomcat?" Watch "Error while accessing servlets from jsp in Tomcat?" New topic
Author

Error while accessing servlets from jsp in Tomcat?

Kumaran Sowrirajan
Ranch Hand

Joined: Oct 15, 2001
Posts: 36
Hi Friends
Can you plz tell me why i am getting this error while accessing the servlets from jsp file in Tomcat Server?
My directory structure is like this in Tomcat >>>>
webapps
--> myproject
--> html
--> images
--> jsp
--> WEB-INF which contains web.xml
--> classes
--> pack1 [package]//servlets

for servlet configuration mine web.xml looks like >>>
<web-app>
<servlet>
<servlet-name>SpecimenComments</servlet-name>
<servlet-class>pack1.specimencomments</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SpecimenComments</servlet-name>
<url-pattern>/specimencomments</url-pattern>
</servlet-mapping>
</web-app>
I am invoking this servlet from jsp file like this >>>>>
<a href="javascript:callcomments();">Comments</a>
<script language="javascript">
function callcomments()
{
document.form1.method = "post";
document.form1.action = "../specimencomments";
document.form1.submit();
}
</script>
note : if you call the servlet like
document.form1.action = "specimencomments"
like this i t will search for the servlet uder the jsp directory.so thats why i am using like this
document.form1.action = "../specimencomments";

only problem is i am not able to access the servlets from jsp file.Tomcat shows error like this >>>>>>>
exception
javax.servlet.ServletException: Error allocating a servlet instance
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:657)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2343)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1012)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1107)
at java.lang.Thread.run(Thread.java:536)

root cause
java.lang.NoClassDefFoundError: pack1/specimencomments (wrong name: specimencomments)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:509)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1631)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:926)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1360)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1243)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:865)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:653)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2343)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1012)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1107)
at java.lang.Thread.run(Thread.java:536)

i am invoking the jsp file as
http://servername:80/myproject/jsp/login.jsp
This will display the jsp file correctly.then after i hit the link generated from this jsp i am calling the servlets.
i dono what is happening there???.
can anybody plz tell me whats wrong i did it here.and plz let me know the directory structure for J2EE deployment is right or wrong??
Thanks and Regards
Kumaran.S
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
Since you defined the servlet as follows:

<servlet>
<servlet-name>SpecimenComments</servlet-name>
<servlet-class>pack1.specimencomments</servlet-class>
</servlet>

It seems to me you should refer to it in the action with "SpecimenComments" not "specimencomments"
Bill
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

Bill is correct. Also, EVEN UNDER WINDOWS, Java is case-sensitive when it comes to filenames. You usually won't see that when doing your own I/O, but the Java classloader won't tolerate incorrect case.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error while accessing servlets from jsp in Tomcat?