I have a jsp that uses a ‘counter’ (Integer) object to keep track of the various pieces of the page that are displayed.
There are three major sections of the page, each implemented using a separate jsp that is jsp:included.
So it basically looks like this:
JSP #1
<html>
<body>
<jsp:include page="include1.jsp" />
<jsp:include page="include2.jsp" />
<jsp:include page="include3.jsp" />
</body>
</html>
I need the çounter to be passed in to the first jsp:include, updated (addition only, if that matters) and have the updated value handed in to the next jsp:include, and then have the newly updated value haded in to the next jsp:include.
So counter starts at 0.
include1.jsp updates this variable to 3.
include2.jsp starts with the value 3 and updates to 5.
include3.jsp starts with the value 5 and updates to 9.
I have this whole setup working well with all the other necessary data that needs to be handed in to the jsp:includes, but I can not for the life of me figure out how to have the /same/ object be used in all places so that it will be updated by the various jsp:includes.
Is this even possible?
Any other way to achieve the functionality I’m looking for? (use a counter across all jsp:includes)
Any and all help will be greatly appreciated.
I solved this problem by passing my value in the request object.
It looks like this:
My main.jsp says:
and my ‘include’ jsps look like this:
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.
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.
Thanks for the help everyone, even though I implemented in a totally different way than suggested.