将服务器端对象从一个JSP页面传递到另一个 [英] Passing server-side objects from one JSP page to another
本文介绍了将服务器端对象从一个JSP页面传递到另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道我可以使用getParameter()传递客户端对象,但是我想知道如何像使用getParameter一样传递服务器端对象.我已经看过getAttribute,但是我需要在第一个JSP页面上使用setAttribute,然后在第二个页面上使用getAttribute.任何帮助将不胜感激.
I know that I can use the getParameter() to pass client-side objects, but I am wondering what to use to pass server-side objects like I do with the getParameter. I have seen the getAttribute but do I need to use the setAttribute on the first JSP page and then the getAttribute on the second page. Any help would be greatly appriciated.
推荐答案
- 如果从一页到另一页使用
forward
(jsp:foprward
或RequestDispatcher
),请使用request.setAttribute(..)
和request.getAttribute()
,因为您属于同一请求 - 如果您正在使用
redirect
(通过response.sendRedirect()
),请使用request.getSession().setAttribute(..)
和request.getSession().getAttribute()
- If you are using
forward
(jsp:foprward
orRequestDispatcher
) from one page to another, then userequest.setAttribute(..)
andrequest.getAttribute()
, because you are within the same request - If you are using
redirect
(viaresponse.sendRedirect()
), then userequest.getSession().setAttribute(..)
andrequest.getSession().getAttribute()
这篇关于将服务器端对象从一个JSP页面传递到另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文