This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes share data from servlet back to jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "share data from servlet back to jsp" Watch "share data from servlet back to jsp" New topic
Author

share data from servlet back to jsp

medswa chan
Greenhorn

Joined: Jul 15, 2011
Posts: 1
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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.
 
 
subject: share data from servlet back to jsp
 
Similar Threads
Session scope form bean problem
UseBean, scope question.
what should i use
setting / accessgin Java Bean between page and servlet.
Jsp and javabean