File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem using bean in jsp file

 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
Hi!
I am new to beans & jsp .I have following problem
1> I created a java file named counter and have used get & set methods.
2> I compiled the java file.
3>I created a jsp file named BeanCounter.jsp and used the counter class using the following code.
<jsp:useBean id="counter" scope="session" class="Counter" />
4> I placed all three files counter.java,counter.class &
BeanCounter.jsp in Counter folder
c:\tomcat\webapps\examples\jsp\Counter
I get the following error
Internal Servlet Error:
org.apache.jasper.JasperException: Unable to load class Counter
please help!
Thanks in advance
Chaitali
 
vik nuckchady
Greenhorn
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error simply says that tomcat can't find the class counter.
May be you must put the class files in some other directory.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Class files do not go into the JSP directory! Don't forget that files in there can be requested by a client - you don't want everyone downloading your class files, do you?
There should be a WEB-INF directory, probably tomcat/webapps/examples/WEB-INF (I don't know Tomcat that well). Class files go into WEB-INF/classes/. Don't forget to turn package names into subdirectories (i.e. com.chaitalid.MyClass would go into WEB-INF/classes/com/chaitalid/).
Should you want to package your classes up in a jar file, the jar would go into WEB-INF/lib/.
- Peter

[This message has been edited by Peter den Haan (edited May 14, 2001).]
 
Frank Carver
Sheriff
Posts: 6920
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"chaitalid",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in with a new name which meets the requirements.
Thanks.
 
Yogesh Kapoor
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all , you must place your class files in the class path of your server. Then the server will always load your custom class and make it available for use in your jsp.
also if you are using package(looks like you kave your class in a package names counter), then you must instantiate the bean using
<jsp:useBean id="counter" scope="session" class="counter.Counter" />
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic