• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Taking Bean value in JSP

 
karthik manick
Ranch Hand
Posts: 53
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..I have a small doubt...

How can i take a bean value in jsp?
If your answer is <usebean>, then i have another doubt.
usually in controller i create a new object like "Bean x= new Bean();" and i will set the values for this bean's object.
How my <usebean> will take exactly the new bean object created in my controller?
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Beans (or objects) set in one of the web scopes (page, request, session, application) are easily accessible via EL.
For example:
 
karthik manick
Ranch Hand
Posts: 53
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My question is, how can i make sure that the new object that i created, is the one which will be retrieved in my jsp.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64204
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You've already been told.

Place the bean in a scope, for example request scope:

Then, forward to the JSP, and in the JSP use the EL:
 
karthik manick
Ranch Hand
Posts: 53
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for all your answers.. But still i have one question... the object which was set in request should be accessed thro request.getParamaeter()? or is there any way to use <usebean> to get the object from request? or any other approach is there?
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you insist on using useBean ? You don't need it here. You access the object via the name you gave to the request attribute. Read Bear's sample one more time.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64204
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
karthik manick wrote:Thanks a lot for all your answers.. But still i have one question... the object which was set in request should be accessed thro request.getParamaeter()? or is there any way to use <usebean> to get the object from request? or any other approach is there?


There's no such thing as <usebean>, it's <jsp:useBean>, and as already pointed out, it's not needed.

Also, getParameter() has nothing to do with any of this. That's for fetching submitted request parameters. It has nothing to do with scoped beans.

 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
karthik, check the link in my first post. It explains what EL, the Expression Language, is. After reading it, you'll understand that you don't need tags or scriptlets to access your scoped attributes.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic