Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet How to search the selected item in row table using radia button in JSP?

Have Programming Question? Ask it here!
 
 
 


shinichiemashita
How to search the selected item in row table using radia button in JSP?
1 Answer(s)      3 years and 4 months ago
Posted in : JSP-Servlet


How to search the selected item in row table using radia button in JSP?


Advertisement
View Answers

April 5, 2011 at 4:39 PM


1)radioselection.jsp:

<%@ page import="java.sql.*" %>
<html>
<form name="form"  method="post" action="search.jsp">
 <table border="1">
<tr><th></th><th>Name</th></tr>
<%
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
String query = "select * from employee";
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(query);
%>
<%
while(rs.next()){
%>
<tr><td><input type="radio" value="<%= rs.getString("id")%>"   name="radio">
<td><input type="text" name="name" value="<%=rs.getString("name")%>"></td>
</tr>
<%
}
%>
<%
}
catch(Exception e){
e.printStackTrace();
}
%>
</table>
<input type="submit" value="Search">
</form>
</html>

2)search.jsp:

<%@ page import="java.sql.*" %>
<form>
<table border=1>
<%
String value=request.getParameter("radio");
int v=Integer.parseInt(value);
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root", "root");
Statement st=conn.createStatement();
ResultSet rs = st.executeQuery("select * from employee where id="+v+"");
if(rs.next()){ 
    %>
<tr><td>Name: </td><td<input type="text" value="<%=rs.getString("name")%>" > </td></tr>
<tr><td>Address: </td><td<input type="text" value="<%=rs.getString("address")%>" > </td></tr>
<tr><td>Contact No: </td><td<input type="text" value="<%=rs.getInt("contactNo")%>" > </td></tr>
<tr><td>Email: </td><td<input type="text" value="<%=rs.getString("email")%>" > </td></tr>
      <%
}
%>
</table>
</form>


Related Tutorials/Questions & Answers:
Advertisements
Advertisements
 

 

 

DMCA.com