aspose file tools*
The moose likes JSP and the fly likes A JavaBean inside a JSP function Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "A JavaBean inside a JSP function" Watch "A JavaBean inside a JSP function" New topic
Author

A JavaBean inside a JSP function

j archie
Greenhorn

Joined: Mar 23, 2004
Posts: 4
Iam using a java beans inside a jsp, this how i did that.
<jsp:useBean id="prm" class="xx.Param" scope="session"/>
In the same jsp file iam defining function (doXX()), which call the bean linked by jsp:useBean tag. Iam getting compilation error.
<%!
public String doXX() {
//some code
String ss = prm.getID(); //??? i think this is where the problem is
}
%>
So my doubt is can we use the instance of java beans inside a jsp function???
Thanks in Advance
Kishore Dandu
Ranch Hand

Joined: Jul 10, 2001
Posts: 1934
It has more to do with compiler not knowing the scope of the names bean class.
Include that package/class at the beginning of your jsp, I think you are all set to go.
Kishore.


Kishore
SCJP, blog
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61756
    
  67

jsp:useBean makes the specified scripting variable available in the main body (service method) of the JSP. It will not be available to declarations.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61756
    
  67

P.S. Take a look at the java file created by the container on the behalf of your JSP. Much will be revealed.
j archie
Greenhorn

Joined: Mar 23, 2004
Posts: 4
Thanks Kishore Dandu & Bear Bibeault,
What should I do to make the bean instance available public.
I added the following snippet to my jsp scriptlet
<% thisBean = myUseBean; %>
and declared thisBean in jspdeclarative statement.
<%! MyUseBean thisBean; %>
it seems to be working fine, but is this a correct way. Please help me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A JavaBean inside a JSP function