aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "problem using bean in jsp file" Watch "problem using bean in jsp file" New topic
Author

problem using bean in jsp file

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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

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
author
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
Sheriff

Joined: Jan 07, 1999
Posts: 6920
"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.

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

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: http://aspose.com/file-tools
 
subject: problem using bean in jsp file