• Post Reply Bookmark Topic Watch Topic
  • New Topic

Retaining values between JSP pages  RSS feed

Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone please help?
Here's the problem I'm having:

I have a user who enters a product number on the JSP page (let's call it page1.jsp). The user hits the submit button and the product number goes to a Java Action class that retrieves the product from a database. The results are stored in a Table. The table is stored in a session in the Java action class like so:
session.setAttribute("tablegrid", table);
The table consists of rows and columns. Rows represent the product's COLORS, and columns represent the SIZES available. The user is then forwarded to page2.jsp, which displays the results in table format. In page2.jsp, the user can enter values in each cell. The values represent quantity. At the bottom of page2.jsp, there's a text box where the user can enter another product number. When the user enters another product number and hits the "next" button, the values for the current product are stored/saved, the Java action class is called again, and the next table is built based on the number you entered and stored in the session. page2.jsp is refreshed with the new table. If the user decides to hit the browser's 'BACK' button while they are in the middle of entering values for this new table, the page should show the previous values the user entered. The user can enter many product numbers and fill in the table values. This can go on until the user hits the "finished" button on page2.jsp, at which time they are directed to summary.jsp. summary.jsp will show a summary of all the tables and values they entered for each cell.

How can I store the values for each product the user enters? What is the best approach? And how can a recall these values if the user hits the back button? I thought about storing the values the user enters in a Hashtable but how do I associate the hashtable with the product number?



<form name="test" action="getproducts.do">
<input type="text" name="products">
<input type="button" value="submit">


<% ResultData tab = (ResultData)session.getAttribute("tablegrid"); %>

<form name="products" action="showproducts.do">
for(int i = 0; i < 10; i++)
{ %>
for(int i = 0; i < tab.getNumRows(); i++) { %>
<td><input type="text" name="<%= tab.getString(i) %>" value=""></td>
<% } %>
} %>

<input type="text" name="nextItem">
<input type="button" value="NEXT">
<input type="button" value="FINISHED">


//Some logic

Hashtable products = new Hashtable();
//This is how I am currently saving the values the user entered
while (enum.hasMoreElements())
String name = (String) enum.nextElement();
if(request.getParameter(name) != null && request.getParameter(name).length() > 0)
products.put(name, request.getParameter(name));

//some more logic
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!