aspose file tools*
The moose likes Servlets and the fly likes How to add beans to JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to add beans to JSP" Watch "How to add beans to JSP" New topic
Author

How to add beans to JSP

jeyaveera pandian
Ranch Hand

Joined: Sep 29, 2000
Posts: 39
Hi Friends,
I found problem in adding beans to JSPs. My problem is, for instance, if I want to add the Juggler bean which is in a file named "juggler.jar" using the <jsp:useBean> tag I am not able to do it. plz tell me the way how to use a bean in JSP
Anbudan
K.Jeyaveerapandian
Brett Knapik
Ranch Hand

Joined: Oct 15, 2000
Posts: 255
try it without the .jar and the class name. it might work or it is not in the right directory of your application server.
------------------
I wish there was a button on my monitor to turn up the intellegince.
Theres a button called 'brightness' but it doesn't work


"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
jeyaveera pandian
Ranch Hand

Joined: Sep 29, 2000
Posts: 39
Hi friend,
Thankyou for your help. But still I am having problems. As i had specified the .class name of the bean instead of the .jar file also I am not able to use that bean. I am using Java Web Server. So. plz tell me where to put my bean in my server's directory? and tell me what to put, the .class file or the .jar file?
Please help me as soon as possible,
Anbudan,
K.Jeyaveerapandian.
Brett Knapik
Ranch Hand

Joined: Oct 15, 2000
Posts: 255
I don't know about jws very much you will have to look for information on where to place your bean in the documentation on sun's website.
------------------
I wish there was a button on my monitor to turn up the intellegince.
Theres a button called 'brightness' but it doesn't work
jeyaveera pandian
Ranch Hand

Joined: Sep 29, 2000
Posts: 39
Hi friends,
Without referring anything, I found how to use bean in JSPs. That is I put my bean's .class file in the same directory of my .jsp file and I used the <%@ import="beanClassName"%> tag before my jsp:useBean tag. In my jsp:useBean tag I wrote like this
<jsp:useBean id="myBean" scope="session" class="beanClassName"/>
I want to know whether this is a proper way or not?! Help me please
Anbudan
K.Jeyaveerapandian
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi Anbudan,
I have been working on JSP for couple of months and have noticed that if your bean class is in a package then you don't need to explicitly import it but if it is not in a package then you need to give the following tag:
<%@ page import="beanClassName" %>
jeyaveera pandian
Ranch Hand

Joined: Sep 29, 2000
Posts: 39
Hi Mathur,
Thanks for your answer. But am still having some doubts. If I am having my beanClass in a package how to call it?
One more personal infromation to you! "Anbudan" is not my name. It means "with love". Anbudan is a word in the language Tamil.
Thanks in advance
Anbudan
K.Jeyaveerapandian
P SOLAIAPPAN
Ranch Hand

Joined: Oct 20, 2000
Posts: 68
Hi Pandian,
You can keep your jar file in classpath sothat the servlet engine can search it or you can keep it where your application keeps all your servlets class files. Like "servlet.jar" you can include your "*.jar" file in classpath in autoexec.bat file.
for example say your bean class is in "bean.jar" which is in d:\beanjars dir then
set classpath=%classpath%;d:\beanjars\bean.jar
Then your JSP engine will search bean.jar also(apart from other classpaths mentioned) for your class file which you are using in <jsp:useBean ........class="..." />
solaiappan
 
 
subject: How to add beans to JSP