Search code examples
javajspatg

Setting parent jsp variables in child jsp


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?


Solution

  • 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") %>