Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Retaining values between JSP pages

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
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?

EX:

page1.jsp

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

page2.jsp


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

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

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

JavaAction.java

//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
 
reply
    Bookmark Topic Watch Topic
  • New Topic