• 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

Passing beans back from the jsp

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm doing this on the jsp:

MyBean mbean = (MyBean)pageContext.getAttribute("myBean", PageContext.REQUEST_SCOPE);
pageContext.setAttribute("myBean",mbean, PageContext.REQUEST_SCOPE);

and back on the server:
MyBean mbean = (MyBean)pageContext.getAttribute("myBean", PageContext.REQUEST_SCOPE);

but the bean is null there. What is the proper way to get a bean back from the jsp? I don't really want split it into field, get them as properties and make the bean again (that is working though).

Thanks for any advice!
 
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
Request scope goes away as soon as the response is sent to the browser. So there is no way for a bean in request scope to magically appear in another, separate request.

You'll either need to use a higher scope (session perhaps), or serialize the data in hidden form elements.
 
Clara Zetkin
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, Bear. I understood REQUEST as passing from one page to the next, but I'll try with SESSION.
 
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
No, that's pretty much what request scope is not. Perhaps you may find this article on JSP life cycles an interesting read.
 
Clara Zetkin
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the link, looks very interesting!
 
Whatever you say buddy! And I believe this tiny ad too:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic