• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Array values from one jsp to other

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Mayank Adhikari
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic