Forums Register Login

share data from servlet back to jsp

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
pie. tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1109 times.
Similar Threads
setting / accessgin Java Bean between page and servlet.
what should i use
Session scope form bean problem
Jsp and javabean
UseBean, scope question.
Thread Boost feature
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 06:24:08.