File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes problem using bean in jsp file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "problem using bean in jsp file" Watch "problem using bean in jsp file" New topic

problem using bean in jsp file

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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.class &
BeanCounter.jsp in Counter folder
I get the following error
Internal Servlet Error:
org.apache.jasper.JasperException: Unable to load class Counter
please help!
Thanks in advance
vik nuckchady

Joined: Apr 25, 2001
Posts: 25
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
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
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

Joined: Jan 07, 1999
Posts: 6920
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at . 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.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Yogesh Kapoor

Joined: May 01, 2001
Posts: 6
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" />
I agree. Here's the link:
subject: problem using bean in jsp file
It's not a secret anymore!