This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes JDBC and the fly likes Trying to display checkbox checked values in new jsp page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » JDBC
Reply locked New topic
Author

Trying to display checkbox checked values in new jsp page

gopi sri
Greenhorn

Joined: Nov 11, 2008
Posts: 6
hello friends

i tried with servlet also. i created seperate file for database connections. still iam facing problem with insertion of checkbox values.

i can able to retrieve the values from database then i stored those values in checkbox. Now the checked values from checkbox should insert into db, here iam facing problem..First iam trying to display the checked values in out.println statement in new jsp page using request.getParameterValues("checkboxname"), but i cannot ablt to pass the values from first jsp page to second jsp page..
here is my code..first.jsp

<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>

<html>
<head>
<title>display data from the table using jsp</title>
</head>
<body>
<h2 align="center"></h2>
<select id="cbosex" name="cbosex">
<option value="true">Male</option>
<option value="false">Female</option>
</option>

<%
try {

Connection con = null;
Statement st= null;
ResultSet rs = null;
String s;


Class.forName("org.gjt.mm.mysql.Driver");
con=DriverManager.getConnection("jdbc:mysql://192.168.1.201:3306/e_busticketing","root","password");
st = con.createStatement();
out.println("connected");
String sql="select seat_no from e_busticketing.seat_mast where bus_id=1001";
rs=st.executeQuery(sql);

%>
<TABLE cellpadding="15" border="1" style="background-color: #ffffcc;" width=20% align="center">
<%
while (rs.next())
{
s=rs.getString("seat_no");

%>
<TR>
<TD><INPUT TYPE=CHECKBOX NAME=c1 value='<%=s%>'><%=s%>


<% } %>


</TD>

</TR>

<%
}
%>
<%
// close all the connections.
rs.close();
st.close();
con.close();

}
catch (Exception ex)
{
%>
</font>

<font size="+3" color="red"></b>
<%
out.println("Unable to connect to database.");
}
%>


</TABLE><TABLE align="center">
<TR>
<TD><FORM ACTION="second.jsp" method=get>

<input type="submit" value="submit">
</TD>
</TR>
</TABLE>
</font>
</body>
</html>

==========================
second.jsp

<html>
<body>
<%! String[] se; %>
<center>
You have selected:

<% se = request.getParameterValues("c1");
if (se != null)
{
for (int i = 0; i < se.length; i++)
{
out.println ("<b>"+se[i]+"<b>");
}
} else
out.println ("<b>none<b>");%>
</center></body>
</html>

regards
gopi
gopinath65@gmail.com
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

Gopi,

Please do not post same problem again.

You have similar post in same forum, I think you solve your previous problem, you will be able to slove this as well. You have not even responded to that post to the people who tried to help you.

Shailesh
[ November 12, 2008: Message edited by: Shailesh Chandra ]

Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trying to display checkbox checked values in new jsp page