This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to store a value so that any JSP page can read it?

 
Nick R Wilson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I’m writing a web application using Struts 1.1. One of the initial web pages displays a grid of rows, loaded from a database table. The primary key of this table is not shown as part of the grid; instead it is displayed as a drop-down box so that only the rows for the selected key will be displayed.

What I want to do is to remember which value has been selected by the user, when they select a different drop-down value, and then choose to go to another page. This primary key is shared by several other tables, and I want it to default to display the corresponding rows with the same selected key, when the user moves to another JSP page.

On the web pages, this drop down box is stored within a form and is changed when the user clicks on the ‘Change’ button. What I need to know is where to store the value, so that it can later be retrieved by a different JSP page. Note that the web page that fails to find the String is not the next page in succession; the selected JSP page is one of several and is chosen via some JavaScript that choose which action to take, e.g.:
<li><a href="#"
onmouseover="mopen('m4')"
onmouseout="mclosetime()">Control Types</a>
<div id="m4"
onmouseover="mcancelclosetime()"
onmouseout="mclosetime()">
<html:link forward="AddCTypeNew">Add Control Type</html:link>
<html:link forward="ListCType">List Control Types</html:link>
</div>
</li>

The code I am using to display the drop down box in the JSP pages is as follows:

<%
String controllerID = (String) System.getProperty("controllerID");
String valSelect = null;
%>
<form action="/GameControls/listBCode.do">
<select name="controllerID">
<c:forEach items="${cTypes}" var="cType">
<c:choose>
<c:when test='${cType.controllerID == controllerID}'>
<c:set var="valSelect" scope="page" value="selected=true" />
</c:when>
<c:otherwise>
<c:set var="valSelect" scope="page" value="" />
</c:otherwise>
</c:choose>
<option <c:out value='${valSelect}'></c:out> value='<c:out value='${cType.controllerID}'></c:out>'>
<c:out value="${cType.controllerDescription}"></c:out></option>
</c:forEach>
</select> <input type="submit" value="Change"></form>


My problem is in storing the String ‘controllerID’. I have tried storing is as a parameter, an attribute, and, in this example, as a System.getProperty. The above code successfully reads from a List of cType objects. But the check as to which value needs the “selected=true” attribute always fails because the controllerID String is always null.

In my struts-config.xml file, here is an example of an action that is called, that tries to retrieve the controllerID String:

<action path="/addBCodeNew" type="filemaint.AddButtonCodePreAction"
name="cTypeForm" attribute="cType" validate="false" scope="session">
<forward name="success" path="/WEB-INF/pages/tiles/buttonCodeAddTiles.jsp" />
</action>

I have tried both ‘session’ and ‘request’ as values for the scope attribute, but neither has worked.

I’m not sure what else to illustrate in regards to my problem. If I’ve missed any important information about my configuration, I’ll happily supply it.
My bottom line questions are:
Why is my controllerID String always null? What is the correct way to store a value submitted to a form, so that any other JSP page can successfully retrieve it?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64708
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to ask Struts questions in the Struts forum. I have moved this post there for you.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to save the value in the action, not on the JSP page.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic