Setting parent jsp variables in child jsp

user1633800 picture user1633800 · Jul 22, 2013 · Viewed 9.9k times · Source

I have a parent jsp a.jsp which includes another jsp b.jsp. I am calculating some values in b.jsp which needs to be used in parent jsp a.jsp , which will pass this calculated value to another jsp say c.jsp. How can I evaluate value in child jsp and pass it to parent jsp before that page completely loads?

Answer

morgano picture morgano · Jul 22, 2013

How are you including the "child" jar inside the parent? static or dynamic import?

if you have

<%@ include file="myFile.jsp" %>

change it by

<jsp:include file="myFile.jsp" />

then in the parent set a property in the request (not in the session, that would be "dirtier"):

<% request.setAttribute("attrName", myValue) %>

finally, in the "child" jsp:

<% myValue = (MyValueType)request.getAttribute("attrName") %>