• 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

Accessing Bean object?

 
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello

I'm trying to understand how beans work in JSP...
now lets imagin we've got the following code... now, does this code actually creates an object of type Address? if so..
Can i access that "address" object and pass it on as a parameter to another method? like...
if thats not possible, then how can i access that object i've been setting to be able to pass it on as a parameter to another method?

Thanks
HannaH

[ November 17, 2007: Message edited by: H Melua ]
[ November 17, 2007: Message edited by: Bear Bibeault ]
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HannaH,
Yes, you can access the variable in a scriptlet. Note that this is a "code smell". Often when you need to put code in a JSP, it is telling you that the code should be somewhere else. For example, maybe a servlet could add the address before forwarding to the JSP. JSPs are better for presentation only.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The useBean tag does quite a bit so it's worth reading up on it if you're going to use it.
There is a link to the JSP spec in my signature.
The section on useBean is both very complete and an easy read.

In short useBean will look for an object of the specified type in the specified scope. If it doesn't find it there, and a 'class' attribute is specified, it will create it, bind it to the specified scope and create a page level variable with the given id that points to it. There's more to it than just that so, again, it's a good idea to read the relevant section in the JSP Spec.
 
H Melua
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jeanne Boyarsky:
HannaH,
Yes, you can access the variable in a scriptlet. Note that this is a "code smell". Often when you need to put code in a JSP, it is telling you that the code should be somewhere else. For example, maybe a servlet could add the address before forwarding to the JSP. JSPs are better for presentation only.




let it smell as long as it works , we'll put the air conditioners on!! :p

to be honest i dont have time to read about servlets or anything else, we've been asked to implement a message board in 2 weeks!! and a week has already gone doing my other java assignment!!

Thanks very much for the straightforward answer...
HannaH
 
H Melua
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ben Souther:
The useBean tag does quite a bit so it's worth reading up on it if you're going to use it.
There is a link to the JSP spec in my signature.
The section on useBean is both very complete and an easy read.

In short useBean will look for an object of the specified type in the specified scope. If it doesn't find it there, and a 'class' attribute is specified, it will create it, bind it to the specified scope and create a page level variable with the given id that points to it. There's more to it than just that so, again, it's a good idea to read the relevant section in the JSP Spec.



Honestly thanks for the summary, i've read the few pages of the link you've provided about jsp:useBean and i must admit i didnt understand everything there since i'm completely new to web applications in general!! but i understand what you've pointed to...

So thanks to you too...
HannaH
 
reply
    Bookmark Topic Watch Topic
  • New Topic