Bookmark Topic Watch Topic
  • New Topic

Trying to display checkbox checked values in new jsp page

 
gopi sri
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Report post to moderator
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 ]
 
    Bookmark Topic Watch Topic
  • New Topic