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

class not found  RSS feed

 
ruijin yang
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
<Problem Summary:If a servlet uses only one
class,we declare that class in web.xml.But,
If a servlet uses more than one class,how to
indicate the path of all classes?>
I use WebLogic6.0.I have a servlet,name ShoppingServlet.
The ShoppingServlet.class is in package shopping. The most
important thing is that ShoppingServlet.class uses CD.class,
which is also located in package shopping.The line
"import shopping.CD;" has been included in ShoppingServlet.java file.
When I run "http://localhost:7001/ShoppingServlet",I got:
ServletException:Servlet class:'shopping.ShoppingServlet' could not
be resolved-a class upon which this class depends was not found.
Maybe I failed to indicate the path of CD.class in WEB-INF\web.xml,
but I don't know how to indicate it.Please help me.
The web.xml is the same as following:
<!--web.xml-->
<web-app>
<servlet>
<servlet-name>ShoppingServlet</servlet-name>
<servlet-class>shopping.ShoppingServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ShoppingServlet</servlet-name>
<url-pattern>ShoppingServlet</url-pattern>
</servlet-mapping>
</web-app>
Thanks in advance.
ruijin yang

[This message has been edited by ruijin yang (edited August 07, 2001).]
[This message has been edited by ruijin yang (edited August 07, 2001).]
[This message has been edited by ruijin yang (edited August 08, 2001).]
 
DAYANAND BURAMSHETTY
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All class files keep into WEB-INF/classes directory.
Ex : (shopping/CD/*.class)this directory keep
into WEB-INF/classes this directory.

 
ruijin yang
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,DAYANAND,
Thank you for your reply.
Yes,I put my classes into WEB-INF\classes\shopping\.In detail,
I have WEB-INF\classes\shopping\ShoppingServlet.class and
WEB-INF\classes\shopping\CD.class.There is not problem about this.As I already indicated the path
of ShoppingServlet.class in web.xml.I just do not know how to
indicate the path of CD.class.I can not add the path of CD.class
into web.xml.
The problem is:How to let WebLogic know the path of
CD.class which ShoppingServlet needs(depends on).
Regards.
ruijin yang
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A servlet expects to find all the classes it needs in:
WEB-INF/classes etc. for loose class files
WEB-INF/lib for .jar files
the JVM's directory for extensions
the JVM's classpath
The WEB-INF locations are part of the Java servlet API specifications. The JVM classpath may be set by some specialized mechanism depending on the server. For example JRun has a properties file.
Bill

------------------
author of:
 
ruijin yang
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I searched in javaranch and I got no answer for this problem.Quite a lot of people encounted same problem.Until now,
People can not get answer from javaranch for this problem.Any one who uses WLS or Tomcat can try this problem.Any one who gets
answer should post it on javaranch.
ruijin yang
 
Tim Holloway
Bartender
Posts: 18662
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We're trying! If I have a utility class in package com.shopping named "CD" and I want it to be visible from any servlet in a web application. I'd set up the directories as follows:

Or put it into a jar file in MyWebApp/WEB-INF/lib/
That's ALL that's required for the classes to be placed in the CLASSPATH for all servlets and JSPs in that web application. You don't have to tell web.xml - the J2EE system knows where to look because it's designed to look there.
Please remember though, that all names in Java are CASE-SENSITIVE! Windows users frequently get burned because the Windows part of their system isn't.
The reason the servlet class is defined in web.xml, BTW, is to map the URL to the servlet - NOT to make it visible/findable.
[This message has been edited by Tim Holloway (edited August 10, 2001).]
[This message has been edited by Tim Holloway (edited August 10, 2001).]
 
ruijin yang
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Holloway,
You are right!With your help,I cleared this problem.Thank you very much.
Two of your points are helpful for me.After reading your post,
I concentrated on my program,not web.xml;I realized that the problem maybe in the package shopping.So I wrote another two
very simple classes which are in the same package to try to know how to use package.Yes,I use package wrong.In my posted problem,I failed to put the line "package shopping;" in the ShoppingServlet.java file.When I added this line into it,the problem disappeared.How wonderful!
ruijin yang
SCJP2
------------------------
<!--Quoted from your post-->
1) You don't have to tell web.xml - the J2EE system knows where to look because it's designed to look there.
2) The reason the servlet class is defined in web.xml, BTW, is to map the URL to the servlet - NOT to make it visible/findable.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!