Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Passing checkbox values from one JSP page to another

Reply
Thread Tools

Passing checkbox values from one JSP page to another

 
 
udelram@gmail.com
Guest
Posts: n/a
 
      05-29-2007
Hi,

I'm trying to get user selections (using checkboxes) on one JSP
page(A.jsp) and pass them on to another page.


So I have one page with a list of dynamically populated items like
this

1 [checkbox]
2 [checkbox]
....
....
n [checkbox]

Submit button

So the second page(B.jsp) needs to say " You selected 1,2,3" (apart
from stuffing them into a database)

Here's a snippet of code from A.jsp

================================================== ======
<% String url = "jdbc:mysql://...";
String user= "";
String pass= "";

try{
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
Connection conn = DriverManager.getConnection(url, user, pass);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM <tablename>");

while(rs.next()){ %>
<table><tr>
<td><b><%= rs.getString("ID") %></b></td>
<td><%= rs.getString("DESCRIPTION") %></td>
<td> <input name="Select" type="checkbox" value="<%=rs.getString("ID")
%> checked"></td>
</tr></table>

<% String selection = rs.getString("ID");
temp = temp + selection + "_";
}
rs.close();
conn.close();
}catch(Exception e)
{out.println(e.toString());
}
%>
</p>
<p>&nbsp; </p>
<form name="form1" method="post" action="B.jsp">
<label>
<input type="submit" name="Select" >
</label>
</form>
</BODY>
================================================== ======

The table in question has 2 columns - ID and DESCRIPTION. I also need
to capture the IDs from all the user selections and pass them on to
page 2 as a string

If the user selects items 1, 2, 3, I need to pass _1_2_3

I'm not familiar with checkboxes and unable to capture only those that
the user selects. In the example above, I'm trying to capture only
those IDs from the checkboxes the user selects under temp. Right now,
every single ID is appended to temp and it looks like _1_2_3_...._n.


Can you pls. take a look at the code?
Thank you for your time!

D.

 
Reply With Quote
 
 
 
 
udelram@gmail.com
Guest
Posts: n/a
 
      05-30-2007
Figured out...

Thanks..

 
Reply With Quote
 
 
 
 
sandy
Guest
Posts: n/a
 
      05-30-2007
On May 30, 7:14 am, (E-Mail Removed) wrote:
> Figured out...
>
> Thanks..


i think by using java script on this check boxes we will get the
boolean as if selected we get true then if checkbox is true then add
it to request as attribute and display them in another jsp.

 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      05-30-2007
sandy wrote:
> On May 30, 7:14 am, (E-Mail Removed) wrote:
>> Figured out...
>>
>> Thanks..

>
> i think by using java script on this check boxes we will get the
> boolean as if selected we get true then if checkbox is true then add
> it to request as attribute and display them in another jsp.


Javascript is not required. Use a controller servlet to decipher the request
parms, then dispatch to the destination JSP with values predefined, say via
request.setAttribute(). Everything can be done server-side with normal HTML
form semantics.

--
Lew
 
Reply With Quote
 
Mirunalini Mirunalini is offline
Junior Member
Join Date: Jun 2011
Posts: 1
 
      06-24-2011
Quote:
Originally Posted by Lew View Post
sandy wrote:
> On May 30, 7:14 am, (E-Mail Removed) wrote:
>> Figured out...
>>
>> Thanks..

>
> i think by using java script on this check boxes we will get the
> boolean as if selected we get true then if checkbox is true then add
> it to request as attribute and display them in another jsp.


Javascript is not required. Use a controller servlet to decipher the request
parms, then dispatch to the destination JSP with values predefined, say via
request.setAttribute(). Everything can be done server-side with normal HTML
form semantics.

--
Lew



i have a main JSP a child JSP,when i click on the button in main form,the child with three check box inputs,based on the selection in the child JSP,the values of the particular fields in parent form should be filled


can u help in that?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JSP and Javascripts on same page (Passing values to JSP fromJavascript) Husain Javascript 3 04-14-2008 10:36 AM
Passing values From One asp.net Page to another TARUN ASP .Net 4 09-19-2007 01:39 PM
JSP (w JSTL) passing arrays from one included page to another kebabkongen@hotmail.com Java 0 12-07-2006 12:53 PM
How to Pass session parameters from one jsp to another jsp sridhar kumar ch Java 1 06-28-2006 05:28 PM
Passing value from one script on one page to another script on another page. Robert Cohen ASP General 3 07-15-2003 01:46 PM



Advertisments