• Post Reply Bookmark Topic Watch Topic
  • New Topic

Accessing Bean object?

 
H Melua
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • 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 ]
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35719
412
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!