passing dynamic value from one jsp page to another using session on button click
<p>I am making a job search web application using java. I have alotted a job id to each job and i am displaying the list of jobs in a bootstrap table from database. on each button click i need to forward this job id to a jsp page where i am adding the applicant name to the database corresponding to the jobs.My code is:</p>

<pre><code>&lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
&lt;%@page import="com.dbutil.CrudOperation"%&gt;
&lt;%@ page import="java.util.*,java.sql.*" %&gt;
&lt;%@ page import="javax.servlet.http.HttpSession" %&gt;


&lt;html&gt;
&lt;head&gt;
      &lt;title&gt;Job List&lt;/title&gt;
  &lt;meta charset="utf-8"&gt;
  &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
  &lt;link rel="stylesheet" href="css/bootstrap.min.css"&gt;
  &lt;link rel="stylesheet" href="css/jobs.css"&gt;
  &lt;script src="jquery.js"&gt;&lt;/script&gt;
  &lt;script src="bootstrap.min.js"&gt;&lt;/script&gt;

&lt;/head&gt;

&lt;body data-spy="scroll" data-target=".navbar" data-offset="50"&gt;

 &lt;% Connection con = null;

            ResultSet rs = null,rs1=null;
            PreparedStatement ps = null;
            HttpSession hs = null;
            hs=request.getSession();
            con = CrudOperation.createConnection();



                %&gt;

&lt;div class="container"&gt;



     &lt;%String strsql = "select * from postjob1 where sr&gt;0";
                    try {
                        ps = con.prepareStatement(strsql);

                        rs = ps.executeQuery(); %&gt;








 &lt;div class="table-responsive"&gt;
  &lt;table class="table table-bordered"&gt;
    &lt;thead&gt;
      &lt;tr&gt;
          &lt;th&gt;Job Id&lt;/th&gt;&lt;th&gt;Job Category&lt;/th&gt;&lt;th&gt;Available Posts&lt;/th&gt;&lt;th&gt;Required Qualifications&lt;/th&gt;&lt;th&gt;Salary Details&lt;/th&gt;&lt;th&gt;Location&lt;/th&gt;&lt;th&gt;Last date of application&lt;/th&gt;&lt;th&gt;&lt;/th&gt;
      &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;% while (rs.next()) {

                %&gt;
    &lt;tbody&gt;

        &lt;tr&gt;&lt;td&gt;&lt;%=rs.getString("id")%&gt;&lt;/td&gt;&lt;td&gt;&lt;%=rs.getString("jobcategory")%&gt;&lt;/td&gt;&lt;td&gt;&lt;%=rs.getString("available")%&gt;&lt;/td&gt;&lt;td&gt;&lt;%=rs.getString("requiredqualification")%&gt;&lt;/td&gt;&lt;td&gt;&lt;%=rs.getString("salarydetails")%&gt;&lt;/td&gt;&lt;td&gt;&lt;%=rs.getString("location")%&gt;&lt;/td&gt;&lt;td&gt;&lt;%=rs.getString("lastdate")%&gt;&lt;/td&gt;&lt;td&gt;&lt;a href="jobDetails.jsp"&gt;&lt;button type="button" class="btn btn-primary" onclick="&lt;% hs.setAttribute("ID",rs.getString("id")); %&gt;" &gt;View Details &lt;/button&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;

    &lt;/tbody&gt;
     &lt;%}
                            } catch (SQLException se) {
                                System.out.println(se);
              }%&gt;
  &lt;/table&gt;

 &lt;/div
&lt;/div&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>I am facing difficulty when I am retreiving the session value ID in other jsp page as i am getting id of the last row in the table irrespective of whichever button i click.Kindly help me run my code.Thanks!</p>