This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
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.
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.