Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ClassNotFoundException: can't find my servlet. Can you help?  RSS feed

 
Carlisia Campos
sanitation engineer
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ClassNotFoundException: can't find my servlet. Can you help?
Hello everyone,
I have a servlet called MemberController under the following default directory in a server that uses Tomcat:
WEB-INF/classes/cs770/project/MemberController
This MemberController class is inside the following package:
package cs770.project;
Currently, I am using the following to call this servlet:
servlet/cs770.project.MemberController
More precisely, this is the complete URL:
http://development.carlisia.com/servlet/cs770/project/MemberController?start=Start+Simulation

On my log file on the server, I am see the error below. I figure my problem is either:
1) I misplaced my servlet (but I don't really think so)
2) I am using the wrong path to call the servlet
3) Something else entirely

I've been reading a lot of documentation, including the server's intructions, and can't figure this one out. If you have any hunch of how to fix this I would appreciate it.
Thank you.

Web Account Init Time: Mon May 05 09:47:25 PDT 2003
Provider URL Binded: rmi://localhost:64700
[Generic DataSource created. It is the preferred means of getting a
database connection in a Java Application. Please refer to the
DataSource topic in the Help Section on how to use.]
******************* Servlet 2.2+ NGASI Engine v2.0 ACTIVATED on: Mon May 05 09:47:26 PDT 2003
java.lang.ClassNotFoundException: Class Not Found: servlet/cs770.project.MemberController
at ngasi.loader.a.loadClass(Unknown Source)
at ngasi.loader.a.loadClass(Unknown Source)
at ezj.g.a.c.a(Unknown Source)
at ezj.g.a.c.int(Unknown Source)
at ezj.d.m.a(Unknown Source)
at ezj.d.m.if(Unknown Source)
at ezj.d.d.(Unknown Source)
at ngasi.loader.ContextLoader.initContext(Unknown Source)
at ngasi.loader.ContextLoader.main(Unknown Source)
[Servlet Error: java.lang.ClassNotFoundException: Class Not Found: servlet/cs770.project.MemberController]
java.lang.NoClassDefFoundError: MemberController (wrong name: cs770/project/MemberController)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:502)
at java.lang.ClassLoader.defineClass(ClassLoader.java:431)
at ngasi.loader.a.a(Unknown Source)
at ezj.engines.EZServletRunner.do(Unknown Source)
at ezj.engines.EZServletRunner.service(Unknown Source)
at ezj.b.a.a(Unknown Source)
at ezj.b.c.handleConnection(Unknown Source)
at ezj.b.e.run(Unknown Source)
******************* Servlet Engine PASSIVATED on: Mon May 05 10:28:45 PDT 2003
 
DC Dalton
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to set up the packaged servlet paths in the web.xml file. like this:
<servlet>
<servlet-name>Servlet_Name</servlet-name>
<servlet-class>fully.quantified.package.name.Servlet_Name</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
I suggest you read the documentation that comes with tomcat for specific instructions on this. What is happening is the engine cant find this because of its packaging. Had it just been a class file that a servlet called you wouldnt have this problem but since its being invoked sirectly from the engine Tomcat needs to know where to look.
 
Carlisia Campos
sanitation engineer
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<servlet>
<servlet-name>MemberController</servlet-name>
<servlet-class>servlet/cs770.project.MemberController
</servlet-class>
</servlet>
That's a good hint. This is what I currently have on my web.xml file. So the "servlet-class" should be:
1) servlet/cs770.project.MemberController
2) cs770.project.MemberController
3) Something else?
Thank you,
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The servlet class must be the package qualified full name of the servlet.
The notation using /servlet/etc. was used alot when servlets first came out as a "convenience" but I suspect it has caused more harm than good. Tomcat used to come with an "invoker" servlet activated by default that detected "/servlet" and loaded your class, but the invoker is off by default in the current Tomcat.
Once you have mapped the servlet class to a servlet name, you can map the servlet name to a url.
Study the examples in web.xml to see how this is done.
Bill
 
Carlisia Campos
sanitation engineer
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep, that did it, thank you.
I mapped my servlet url pattern to "/ccservlet" and whenever I called the servlet I had to use the path "../ccservlet".
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!