[英]how to retrieve data from html table and send it to another jsp page?
Here is the table, now I want to send the value of sno column to another jsp page. 这是表,现在我想将sno列的值发送到另一个jsp页面。
I have created a hyperlink in the form of buttons and I want to send the value while clicking on the button. 我已经创建了按钮形式的超链接,我想在单击按钮时发送值。
<table id="table" border="5" cellspacing="2" cellpadding="15">
<thead>
<tr>
<th>S.No</th>
<th>Company Name</th>
<th>Created By</th>
<th>Company Address</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<%
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/assignment","root","root");
Statement st = con.createStatement();
ResultSet rs=st.executeQuery("select * from company");
int count=0;
while(rs.next())
{
out.println("<tr>");
out.println("<td>"+rs.getString("sno")+"</td>");
out.println("<td>"+rs.getString("company_name")+"</td>");
out.println("<td>"+rs.getString("userid")+"</td>");
out.println("<td>"+rs.getString("company_address")+"</td>");
String a=rs.getString("status");
if(a.equals("Unapproved"))
{
out.print("<td><a href='edit.jsp'><input type='submit' value='Edit'></a>   <a href='delete.jsp'><input type='submit' value='delete'></a>   <a href='approve.jsp'><input type='submit' value='Approve'></a></td>");
}
else
{
out.print("<td><a href='edit.jsp'><input type='submit' value='Edit'></a>   <a href='delete.jsp'><input type='submit' value='delete'></a></td>");
}
out.println("</tr>");
count=1;
}
if(count==0)
{
out.println("NO RECORD'S FOUND");
}
%>
</tbody>
</table>
For example you can put the ResultSet into your Session and read it in another JSP. 例如,您可以将ResultSet放入Session中,并在另一个JSP中读取它。
Save to session: session.setAttribute("resultset", rs);
保存到会话: session.setAttribute("resultset", rs);
Read from session: ResultSet rs = (ResultSet) session.getAttribute("resultset");
从会话读取: ResultSet rs = (ResultSet) session.getAttribute("resultset");
You may append the sno
as query string in the link itself: 您可以将sno
作为查询字符串附加在链接本身中:
String sno = rs.getString("sno");
out.println("<td>"+sno+"</td>");
...
out.print("<td><a href='edit.jsp?sno="+sno+"'><input type='submit' value='Edit'></a>   <a href='delete.jsp?sno="+sno+"'><input type='submit' value='delete'></a>   <a href='approve.jsp?sno="+sno+"'><input type='submit' value='Approve'></a></td>");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.