File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "variables in jsp" Watch "variables in jsp" New topic

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++)
<tr height=10>
<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

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: 160
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

Joined: Jan 10, 2002
Posts: 63870

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] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63870


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

You want to be using getParameterValues() for this.
I agree. Here's the link:
subject: variables in jsp
It's not a secret anymore!