Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I solved this problem by passing my value in the request object. </p> <p>It looks like this:</p> <p>My main.jsp says:</p> <pre><code>&lt;% int counter = 0; request.setAttribute("counter", counter); %&gt; &lt;jsp:include page="include1.jsp"&gt; &lt;jsp:param name="counter" value="&lt;%=request.getAttribute("counter")%&gt; /&gt; &lt;/jsp:include&gt; &lt;jsp:include page="include2.jsp"&gt; &lt;jsp:param name="counter" value="&lt;%=request.getAttribute("counter")%&gt; /&gt; &lt;/jsp:include&gt; &lt;jsp:include page="include3.jsp"&gt; &lt;jsp:param name="counter" value="&lt;%=request.getAttribute("counter")%&gt; /&gt; &lt;/jsp:include&gt; </code></pre> <p>and my 'include' jsps look like this:</p> <pre><code>&lt;% Integer counter = Integer.valueOf(request.getParameter("counter")); %&gt; &lt;!-- do my stuff, sometimes manipulating the 'counter' Integer object --&gt; &lt;% request.setAttribute("counter", counter); %&gt; </code></pre> <p>You can see how this works. The main page passes the value of the counter object as a param to the first includeX.jsp, which pulls the param out of the request and uses it. Then at the end of the includeX.jsp it sets the current value of the counter in the request attributes. When the main.jsp picks it up again it pulls the value from the request attributes to hand in to the next includeX.jsp as a param again. </p> <p>At one point I did have it implemented /all/ using request.get/setAttribute calls rather than the stuff, but it seemed to indicate the flow better to pass it as a parameter rather than pull it from the request object. I don't really know the pros/cons of either approach but this is working for me now.</p> <p>Thanks for the help everyone, even though I implemented in a totally different way than suggested.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload