title: Session Setattribute is taking only last value from the loop
body: <p>This is my Jsp code ,Here I get list of jobs and when I click it it should send the jobid as session to next jsp</p>
  
  <pre><code>&lt;%
      ArrayList jobs = new ArrayList();
      jobs = master.getJobList(candidate.getEmailId());
  
      if (!jobs.isEmpty()) {
          for (int i = 0; i &lt; jobs.size(); i++) {
              jobs.get(i).getJobTitle().toUpperCase().charAt(0);
  %&gt;
  &lt;div class="box inner" id="jobdetail&lt;%=i%&gt;"&gt;
      &lt;span class="pull-left img-circles" id="titleChar&lt;%=i%&gt;"&gt; &lt;%=jobs.get(i).getJobTitle().toUpperCase().charAt(0)%&gt;
      &lt;/span&gt;
  &lt;/div&gt;
  
  &lt;script&gt;
                                      $("#jobdetail&lt;%=i%&gt;").click(function() {
                                      &lt;%String jobid = jobs.get(i).getJobId();
                      session.setAttribute("jobid", jobid);%&gt;
                                          //var jobid=$("#jobid&lt;%=i%&gt;").val();                                                 
                                          //sessionStorage.setItem("jobid","jobid");
                                          alert("&lt;%=jobs.get(i).getJobId()%&gt;
      ");
  
                          window.location.location("jobdetail.jsp");
                      });
  &lt;/script&gt;
  &lt;%
      }
      } else {
  
          out.println("No Applied Jobs ");
  
      }
  %&gt;
  </code></pre>
  
  <p>In the <code>jobdetail.jsp</code> I have added <code>session.getAttribute("jobid")</code>.If 5 jobs are displayed when I click one of the jobs  it returns only the job id of the last one  ,I added an alert box to check and the alert box returns the correct job id but the session attribute always stores the jobid of last one and I am not able to get other jobid's how can i sort this problem</p>