0

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>
Valijon
  • 12,667
  • 4
  • 34
  • 67
  • You can add parameters to your `*.jsp?param1=value1&param2=value2` [https://stackoverflow.com/questions/1890438/how-to-get-parameters-from-the-url-with-jsp](https://stackoverflow.com/questions/1890438/how-to-get-parameters-from-the-url-with-jsp) – Valijon Sep 27 '18 at 10:15

2 Answers2

0

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");

Danny.
  • 363
  • 1
  • 4
  • 23
MyOggRadio
  • 34
  • 10
  • 1
    Maybe the ResultSet is not a good Option to be stored in the Session because it vanishes if you close the Connection. But you can put all sno columns in an ArrayList and store it in the session. – MyOggRadio Sep 27 '18 at 08:56
  • and can I create more than one connection ? because I have created the session already – Ayush Goyal Sep 29 '18 at 03:23
  • A Connection is not a Session. A Session is created by your Application Server. And you can use it to store a lot of Things. – MyOggRadio Sep 29 '18 at 09:32
0

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>");