• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A JavaBean inside a JSP function

 
j archie
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1934
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64715
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jsp:useBean makes the specified scripting variable available in the main body (service method) of the JSP. It will not be available to declarations.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64715
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic