tags:

views:

24

answers:

1

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 the data?

+2  A: 

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 an 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}

Bozho