Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem recognizing package by Tomcat 5.0  RSS feed

 
Katja Ivanova
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hallo !
I have a servlet that uses a package "Servlet" and Tomcat doesn't want to recognize the package.
my web.xml looks like this:
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

<display-name>Test2</display-name>
<description>
Test2 lang
</description>

<servlet>
<servlet-name>Servlet.testservlet</servlet-name>
<servlet-class>testservlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Servlet.testservlet</servlet-name>
<url-pattern>/servlet/testservlet</url-pattern>
</servlet-mapping>

</web-app>

and the error message from Tomcat looks like this:
java.lang.NoClassDefFoundError: testservlet (wrong name: Servlet/testservlet)
java.lang.ClassLoader.defineClass0(Native Method)
java.lang.ClassLoader.defineClass(Unknown Source)
java.security.SecureClassLoader.defineClass(Unknown Source)
org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1653)
org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:883)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1333)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1213)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:164)
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:211)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:805)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:696)
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:605)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:677)
java.lang.Thread.run(Unknown Source)

so can anyone please tell me what I'm doing wrong

thanks & Regards
Katja
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



You've got it backwards. You fully qualify the servlet-class

Try:



Also, if you're mapping your servlets, there is no need to put '/servlet' into the url. Just put the pattern you want to use.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's also a good idea to follow the standard capitalization standard.

All letters in package name are lower case.
Classnames start with an upper case letter.

It's especially helpful in here where other developers are trying to read your code.
 
Katja Ivanova
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot, that really solved the problem!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!