简体   繁体   中英

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.

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> &nbsp&nbsp<a href='delete.jsp'><input type='submit' value='delete'></a> &nbsp&nbsp<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>&nbsp&nbsp <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.

Save to session: session.setAttribute("resultset", rs);

Read from session: ResultSet rs = (ResultSet) session.getAttribute("resultset");

You may append the sno as query string in the link itself:

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> &nbsp&nbsp<a href='delete.jsp?sno="+sno+"'><input type='submit' value='delete'></a> &nbsp&nbsp<a href='approve.jsp?sno="+sno+"'><input type='submit' value='Approve'></a></td>");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM