Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

share data from servlet back to jsp

 
medswa chan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, i wanted to know what is the best practice to share data between the servlet and jsp. in my project which was wriiten years back they use a lot of usebean in session, when it is not required in session scope. url rewriting doesnt always help as we cant keep passing stuff everywhere. i need a bean to be available in a series of back and forth calls between jsp and servlet , and i put it in the session scope, the first time it works but the second time when it hits the servlet where i update the session again and come bac to the same jsp, the session is not getting updated (i use tomcat). i tried manually removing it from session and putting it back again, but doesnt work. so i am wondering if there is some other way or should i use request scope for the bean. please help.
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the session is forwarding to the JSP, then putting data into the request scope is sufficient.

If you are talking about preserving data from one request to the next, then you will have to put data into the session scope to preserve it.

Those are the "best practices" summarized in two sentences.

However you will have to look at your system and identify the request life-cycle. As it is we just have some sloppy talk about passing data from servlets to JSPs without any information about the requests involved. When I see you saying that a servlet "calls" a JSP, or vice versa, it's pretty clear that you aren't looking at the system properly.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic