• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Taking Bean value in JSP

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic