File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Passing data from servlet to JSP to servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Passing data from servlet to JSP to servlet" Watch "Passing data from servlet to JSP to servlet" New topic

Passing data from servlet to JSP to servlet

Ron Rea

Joined: Jul 03, 2001
Posts: 23
I am trying to pass an arraylist, created in a servlet, to the JSP (where its propertys are displayed and modified), then back to the servlet.
I am using this to pass the arraylist in the Action:
request.setAttribute(Constants.GRID_DETERMINATIONS_ARRAY_LIST, determinationsArray);
The JSP iterated through this and places its properties on the page:
<logic:iterate id="gridDeterminations"
But I cannot get this ArrayList back when I hit submit and execute a request.getAttribute within the Action. It comes back as null.
Any help would be GREATLY appreciated!!
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
Putting objects in request scope means that they are only available for the lifetime of the request. In other words, from when the request comes in to the web server, until the response is sent back.
Judging by your question, it sounds as if the data is going to the user and then they are submitting another request. If you need to maintain state over multiple requests, you should consider using a wider scope such as session.
Hope that helps...
Ron Rea

Joined: Jul 03, 2001
Posts: 23
Thanks very, very much for your reply!
I put the arraylist in session scope and now am able to pull it back in via a session.getAttribute.
One more question - although the JSP displays the arraylist properties, at which time I will make changes to a property and hit submit, when the action gets the arraylist (via the session.getAttribute) the changes are not there. Is there a step in the JSP that I am missing, like a setProperty, etc...
Thanks in advance!
example of JSP iterate:
<logic:iterate id="gridDeterminations"
<td><bean:write name="gridDeterminations" property="messageCode" filter="true"/> </td>
<td><bean:write name="gridDeterminations" property="messageDesc" filter="true"/> </td>
<td><bean:write name="gridDeterminations" property="messageSeverity" filter="true"/> </td>
<html:select property="processResp" size="1">
<htmlption value=""></htmlption>
<htmlption value="CMPLD">CMPLD</htmlption>
<htmlption value="OIS">OIS</htmlption>
<htmlption value="RDA">RDA</htmlption>
<htmlption value="BMA">BMA</htmlption>
<htmlption value="PMA">PMA</htmlption>
<htmlption value="DEN">DEN</htmlption>
<html:radio property="overrideInd" value="A"/>Approve
<html:radio property="overrideInd" value="D"/>Deny
<td> </td>
I agree. Here's the link:
subject: Passing data from servlet to JSP to servlet
jQuery in Action, 3rd edition