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" ?
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
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards

This thread has been viewed 998 times.

All times above are in ranch (not your local) time.
The current ranch time is
Sep 20, 2018 10:33:24.