This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

variables in jsp

 
Brandon Broschinsky
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64851
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64851
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
P.S.

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


You want to be using getParameterValues() for this.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic