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 thedoGet(..)
method of the generated servlet (each JSP is converted to a servlet), so logically, the originalrequest
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 aServletRequest
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}
.
精彩评论