开发者

Jsp include, forwarding request parameter

开发者 https://www.devze.com 2023-01-21 09:19 出处:网络
In my jsp file I am pulling data from the request via request.getAttribute(). Inside this jsp I need to include another jsp.Will this inluded jsp have access to the request, or do I need to somehow f

In my jsp file I am pulling data from the request via request.getAttribute().

Inside this jsp I need to include another jsp. Will this inluded jsp have access to the request, or do I need to somehow forward on 开发者_StackOverflow社区the data?


It will be available:

  • if you are doing a static include (<%@ include file=".." %>) then the body of the included file is placed into the doGet(..) method of the generated servlet (each JSP is converted to a servlet), so logically, the original request object is accessible there.

  • if you are doing a dynamic include (<jsp:include>), RequestDispatcher.include(..) is used (behind the scene). As you can see, it requires a ServletRequest parameter, which would mean that the original request is passed there.

Finally, avoid using Java code in JSP files. Use EL and JSTL. So instead of request.getAttribute("x") this would be ${x}.

0

精彩评论

暂无评论...
验证码 换一张
取 消