• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

jsp:useBean

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

Can someone help me in understanding the scope attribute of jsp:useBean tag. If I set the scope to session, would the bean property be accesible using jsp:getProperty tag from any jsp file? Also shd I have the jsp:useBean re-declared in the pages that I would be accesing the property? This is my understanding, but when I tried out with a code, I get the value as null.

Code where I am setting the bean values.


Code 1 - where I access it. It works fine here.



Code 2 - Here I am trying to acess the session bean and it does not work.
I get the value as null


Pls help.

Thanks and Regards,
Ramya.
 
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your servlet, you are storing the Person in the Request object not the Session object:



Also, in your first JSP, you are creating a bean, storing it in the session and populating it from Person in the request object. So, yes, you will see the value when you call getProperty.

In your second JSP, you are creating a bean, storing it in the session but never populating it. (There is no setProperty tag.) So, no, you will not see the value when you call getProperty.

The above assumes that you start a new session then call the servlet which forwards to one of the JSPs. (The useBean tag will check the Session for an existing Person and use that if it exists, but it won't in a new session.)

Suppose you change the scenario such that the servlet executes and forwards to JSP 1 and then you call JSP 2 in the same session. In this case, you would see the name displayed in JSP 2 because JSP1 would have stored a populated Person object in the Session.
 
Seriously Rick? Seriously? You might as well just read this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic