Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Errror in deploying servlet: wrong name: TestServlet

 
akshay ranganath
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am learning Servlets. I created a servlet called TestServlet in a class akshay.

The URL for the servlet is http://localhost:8080/Test/testServlet?name=aaa&password=aaa

The deployment structure looks like:
webapps/WEB-INF/classes/akshay/TestServlet.class

The Web.xml has the following lines:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "file:C:\Java\web-app_2_3.dtd">

<web-app>
<servlet>
<servlet-name>testServlet</servlet-name>
<servlet-class>akshay.TestServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>testServlet</servlet-name>
<url-pattern>/testServlet</url-pattern>
</servlet-mapping>
</web-app>

I got this error:

exception

javax.servlet.ServletException: Error allocating a servlet instance
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
java.lang.Thread.run(Thread.java:534)

root cause

java.lang.NoClassDefFoundError: akshay/TestServlet (wrong name: TestServlet)
java.lang.ClassLoader.defineClass0(Native Method)
java.lang.ClassLoader.defineClass(ClassLoader.java:539)
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1634)
org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:860)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1307)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1189)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
java.lang.Thread.run(Thread.java:534)

Could you please help me out in resolving this?

Thanks,
Akshay
 
pawank gupta
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
akshay is ur class of ur package. if it is a class then how could u run the servlet. a servlet is independent class
 
Gadi Reddy
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check your classs name and servlet-name.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a problem with the way you have set up your package and compiled the class. Make sure the class is declared 'package akshay;' at the start, and make sure it is compiled as askay/TestServlet.java and not just TestServlet.java
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pawank gupta
Welcome to JavaRanch!

In an effort to help you get the most from our forums, we've compiled a
list of tips for posting here. You can find the list in our
FAQ section here. In particular, please see UseRealWords.

Abbreviations such as "ur" instead of "you are" or "you're" confound lnaguage translation software making it difficult or impossible for our non-English speaking members to read your posts.

Again, welcome to JavaRanch and thank you for helping out.
-Ben
 
akshay ranganath
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for the help...
The problem turned out to be something else altogether - I was using eclipse for development/compiling. There seems to be a strange error in it.

Unless I save a file and then re-compile, it is not detecting the changes, even though "Build Automatically" option was set. When I started to this, the problem got resolved.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic