[Logo]
Forums Register Login
Should use req.setAttribute() or res.setAttribute() ?
If "MyJsp1.jsp" is redirected to "MyServlevt.java" by clicking "Action=...", and then in "MyServlevt.java" I want to pass an object from this servlet to another jsp page "MyJsp2.jsp" by using "forward(req, res)", then should I use "req.setAttribute()" or "res.setAttribute()" in "MyServlet.java" servlet to send the obj to "MyJsp2.jsp" ?
thanks.
Hi,
There are three ways..to pass object from servlet to JSP.
01) set in application level. - avaiable to whole application.(in this u can always set Database connection object or something else which your application is sharing)

02) set in session - for each client session will be different.
03) Set in request- request.setAttribute("",...)
Its all depend on your problem secnario..pls see which one fits in your problem.
Take care
Message for you sir! I think it is a tiny ad:
ScroogeXHTML 7.1 - RTF to HTML5 / XHTML converter
https://coderanch.com/t/690611/ScroogeXHTML-RTF-HTML-XHTML-converter


This thread has been viewed 929 times.

All times above are in ranch (not your local) time.
The current ranch time is
Feb 18, 2018 17:18:51.