Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Should use req.setAttribute() or res.setAttribute() ?  RSS feed

 
Ian Yang
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
james edwin
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!