File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Taking Bean value in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Taking Bean value in JSP" Watch "Taking Bean value in JSP" New topic
Author

Taking Bean value in JSP

karthik manick
Ranch Hand

Joined: Aug 25, 2009
Posts: 52
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

Joined: Nov 24, 2005
Posts: 14688
    
  16

Beans (or objects) set in one of the web scopes (page, request, session, application) are easily accessible via EL.
For example:


[My Blog]
All roads lead to JavaRanch
karthik manick
Ranch Hand

Joined: Aug 25, 2009
Posts: 52
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

Joined: Jan 10, 2002
Posts: 61606
    
  67

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:


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
karthik manick
Ranch Hand

Joined: Aug 25, 2009
Posts: 52
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

Joined: Nov 24, 2005
Posts: 14688
    
  16

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

Joined: Jan 10, 2002
Posts: 61606
    
  67

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

Joined: Nov 24, 2005
Posts: 14688
    
  16

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
 
subject: Taking Bean value in JSP