aspose file tools*
The moose likes JSP and the fly likes Array values from one jsp to other Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Array values from one jsp to other" Watch "Array values from one jsp to other" New topic
Author

Array values from one jsp to other

Mayank Adhikari
Greenhorn

Joined: Nov 17, 2012
Posts: 12
Hi I am creating a Webpage where user can select 12 Players names from drop down column and fill their other details and then "submit" to make database entries. I want to take the values and the drop down selections in arrays and make a database entry from other JSP page. can some one suggest how to take these values to other jsp page.


My first JSP: Here i am having two variable Stat_Player_name & U_RUNS which were used 12 times for storing player name & player runs.

<form name="Team_Playerdetails" method="post" action="db_Match_Edit.jsp">
<TABLE>
<% for(int j=0;j<12;j++)
{ %>
<TR>
<TD>
<SELECT name="Stat_Player_name">
<% for(int i=0;i<20;i++)
{ %>
<option>
<% out.println(Match_List[i][1]); %>
</option>
<% } %>
</SELECT>
</TD>
<TD>
<input type="text" name="U_RUNS" tabindex="1" size="10"/>
</TD>
</TR>
<%} %>
</TABLE>
<input type="submit" name="submit" value="Add All" tabindex="10" class="button" />
</form>

Now please let me knwo how to take the selected values to ther jsp page
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61432
    
  67

You should not be submitting the form to a JSP, you should submit the form to a servlet. The servlet can gather the data and send it to a model class for persisting to the database.

What part of the process is befuddling you?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mayank Adhikari
Greenhorn

Joined: Nov 17, 2012
Posts: 12
Thanks for the reply. Sorry i am new in jsp and don't have much idea. So just let me clarify my requirment.

Say i have a program as below. Where i am having a "First.jsp" where there is an array as Match_List[5].

String[]Match_List;

Match_List[]={a,b,c,d,e};

<form name="Team_Playerdetails" method="post" action="db_Match_Edit.jsp">
<TABLE>
<% for(int j=0;j<10;j++){ %>
<TR>
<TD>
<SELECT name="Stat_Match_name">
<% for(int i=0;i<5;i++){ %>
<option>
<% out.println(Match_List[i][1]); %>
</option>
<% } %>
</SELECT>
</TD>
</TR>
<%} %>
</TABLE>
<input type="submit" name="submit" value="Add All" tabindex="10" class="button" />
</form>

Now this above form will display a same drop down lists 10 times. i want to select different options in these ten lists say like below:
List_1 Option: a
List_2 Option: d
List_3 Option: e
List_4 Option: b
List_5 Option: c
.....
List_10 Option: d

Now i need that once user click the submit butten then the variable should be moved to "db_Match_Edit.jsp". Here i will have the code to catch the value as
U_Stat_Match_name=request.getParameter("Stat_Match_name");

But since all the 10 drop down options are getting catch by same select variable name "Stat_Match_name". So on "db_Match_Edit.jsp" i am only getting the last selected option in U_Stat_Match_name.
But i need all the 10 selected options in the "db_Match_Edit.jsp" jsp in an array.


Your help will be really appreciated.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61432
    
  67

A few things:

Firstly, if you are new to JSP you need to know that you are doing it wrong from the start! You are using Java scriptlets in your JSP which have been obsolete and discredited for over 10 years. Please read this JspFaq entry. You should be using the JSTL and EL and not be putting any Java code in your JSPs.

Secondly, please UseCodeTags when posting code. Unformatted code is very hard to read.

Next, why are all the select options named the same? Give them different names if they represent different values. If they represent the same value, use the proper method for the request in your servlet to fetch the multiple values (search the javadoc for the available methods).

And, never ever name anything "submit" in your HTML. That's a reserved name. Change the name of the button immediately.

And finally, again, do not submit your form to a JSP. Ever. Submit it to a servlet. Always.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Array values from one jsp to other