Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error: IllegalName: /SearchServlet

 
J Derzaph
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I've seen this error in a couple of other posts but the solution doesn't work for me. My xml is a little different so I'll post it.

<servlet>
<servlet-name>SearchServlet</servlet-name>
<servlet-class>.SearchServlet</servlet-class>
<servlet>
<servlet-mapping>
<servlet-name>SearchServlet</servlet-name>
<url-pattern>/SearchServlet</url-pattern>
</servlet-mapping>

And here's the error I get:
exception

javax.servlet.ServletException: Error allocating a servlet instance
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:535)
org.apache.catalina.authenticator.SingleSignOn.invoke(SingleSignOn.java:417)
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:300)
org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:374)
org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:743)
org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:675)
org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:866)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
java.lang.Thread.run(Thread.java:595)


root cause

java.lang.NoClassDefFoundError: IllegalName: /SearchServlet
java.lang.ClassLoader.preDefineClass(ClassLoader.java:476)
java.lang.ClassLoader.defineClass(ClassLoader.java:614)
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
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)
java.security.AccessController.doPrivileged(Native Method)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:535)
org.apache.catalina.authenticator.SingleSignOn.invoke(SingleSignOn.java:417)
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:300)
org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:374)
org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:743)
org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:675)
org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:866)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
java.lang.Thread.run(Thread.java:595)

What's really annoying about it is that the app works perfectly well on my computer locally but when I uploaded the files to a web server I get this error. I suspect the versions are different.
Any suggestions?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Typo? A class name can't start with a dot. It needs to start with the package name if it is in a package or just the class name if it is not.
 
J Derzaph
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops. That's not supposed to be there. It has the error without the dot though.
 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by J Derzaph:
Oops. That's not supposed to be there. It has the error without the dot though.



So the real servlet isn't in a package? What version of Tomcat? With some combinations of servers and JDKs you need to put the Servlet in a package for it to be recognized.
[ September 05, 2008: Message edited by: Steve Luke ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the servlet in a package? If not, put it in one to eliminate that as a source of error.
 
J Derzaph
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have another servlet that is set up the same way and is running just fine though so I don't think its an issue with packages.
the version of Tomcat on the server is 5.0.27.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Servlets that are not packaged may or may not work. Not only is it a poor practice to have unpackaged classes, eliminating that as a source of error is just common sense.

Why would you not follow this accepted practice?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13056
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have another servlet that is set up the same way and is running just fine though so I don't think its an issue with packages.


When a JVM sees a class without a named package (ie, the default package) it looks for that class in the "current" directory. Depending on the "current" directory to always be correct leads to exactly the problem you have.

This is a well known and frequently remarked on trap for programmers new to servlets.

Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic