• Post Reply Bookmark Topic Watch Topic
  • New Topic

Passing beans back from the jsp  RSS feed

 
Clara Zetkin
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • 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!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks for the link, looks very interesting!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!