wood burning stoves 2.0*
The moose likes JSP and the fly likes variables in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "variables in jsp" Watch "variables in jsp" New topic
Author

variables in jsp

Brandon Broschinsky
Ranch Hand

Joined: Aug 21, 2004
Posts: 41
I am writing a small program in jsp. This is my first time doing so although i have done much java programming. I basically have a form, right now on 4 jsp pages, and when the user is done filling in the information on the form I am going to write it out to a file. The problem I am having is with creating dynamic data. That is why I have so many jsp pages. Ex. in one text the field the user enters a number for a specific number of records they are going to enter. I then need to generate the text boxes for them. I have them enter the number on one page and genereate the boxes on another. That works but then trying to store the values in text boxes becomes a problem because I don't know how many boxes they need. Right now I am using a for loop to generate the boxes like so.
for(int i=0;i<arraySize;i++)
{
if(i%7==0)
{%>
<tr height=10>
<td></td>
<td colspan=2><hr width="100%" size="1" noshade/> </td>
<%}
String temp = Integer.toString(payRecordCount); //generate unique name for text box
String temp2 = "payRecord"+temp;
%>
<input type="text" name="<%=temp2%>" size="10"> //having trouble retrieving this value
    <%out.print(field[(i%7)]);
payRecordCount++;%><br>
<%
}

and on another page trying to retrieve the data in the box by calling
payRecord[i] = request.getParameter("temp");

where payRecord is an array to hold all the values and temp is a string that gets set to equal "payRecord#" where # is a number to match the number from the above code. I continue to recieve 'null' values. Any help or suggestions on a better way to approach this would be appreciated.
Senthil B Kumar
Ranch Hand

Joined: Feb 09, 2004
Posts: 140
There is a concept called Control Arrays in Web Programming (you can consider it as either in HTML/Scripting)

for example, if you define multiple text box with same name "MyTextBox". Then an Array of Text Box objects is created and the array name is "MyTextBox", now to get the value of the first textbox in this array, we can say MyTextBox[0] and so on.

So try using CONTROL ARRAYs.


Work like you don't need the money. Love like you've never been hated. Dance like nobody's watching. Sing like nobody's listening. Live like it's Heaven on Earth.
Currently I Reside Here WEBlog
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61310
    
  66

Rather than spreading the form artificially across multiple pages, you coud refresh the page as necessary with the updated controls, or use the XMLHttpRequest mechanism to call back to the server without refreshing the entire page.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61310
    
  66

P.S.

payRecord[i] = request.getParameter("temp");


You want to be using getParameterValues() for this.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: variables in jsp