title: How do I set a session variable via <c:set within a link in JSTL/JSP?
body: <p>I'm having problems in knowing what row has been selected when using the <code>&lt;c:forEach</code> tag in JSTL/JSP page.</p>
  
  <p>The below is the snippet from my JSP page, that successfully prints out all the Users that I have from my session variable. Also included in the UserList class is the userId that corresponds to the rowID in the database.</p>
  
  <pre><code>        &lt;tbody&gt;
              &lt;c:forEach items="${userList}" var="user"&gt;
                  &lt;tr&gt;      
                      &lt;td&gt;${user.firstName}&lt;/td&gt;
                      &lt;td&gt;${user.lastName}&lt;/td&gt;
                      &lt;td&gt;${user.email}&lt;/td&gt;
                      &lt;td&gt;&lt;a href="#UploadModal" data-toggle="modal"&gt;&lt;c:set var="selectedUser" value="${user.userId}" scope="request" /&gt;Upload a File&lt;/a&gt;&lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/c:forEach&gt;
          &lt;/tbody&gt;
  </code></pre>
  
  <p>The modal link is a pop-up modal from twitter Bootstrap.</p>
  
  <pre><code>    &lt;div id="UploadModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"&gt;
          &lt;div class="modal-header"&gt;
              &lt;button type="button" class="close" data-dismiss="modal" aria-hidden="true"&gt;×&lt;/button&gt;
              &lt;h3 id="myModalLabel"&gt;Upload Document for User &lt;c:out value="${requestScope.selectedUser}"&gt;&lt;/c:out&gt;&lt;/h3&gt;
          &lt;/div&gt;
          &lt;div class="modal-body"&gt;
              &lt;form method="post" action="${pageContext.request.contextPath}/upload" enctype="multipart/form-data"&gt;
                  &lt;table border="0"&gt;
                      &lt;tr&gt;&lt;td&gt;File:&lt;/td&gt;
                          &lt;td&gt;&lt;input type="file" name="photo" size="50"/&gt;&lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;&lt;td colspan="2"&gt;&lt;input type="submit" value="Save"&gt;&lt;/td&gt;&lt;/tr&gt;
                  &lt;/table&gt;
              &lt;/form&gt;
          &lt;/div&gt;
          &lt;div class="modal-footer"&gt;
              &lt;button class="btn" data-dismiss="modal" aria-hidden="true"&gt;Close&lt;/button&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>What I wanted to do was that the rows of all users are displayed. There's a link next to each one, that when you click it pops up the modal form, and then the UserId is included in the session variable and also displayed. When it comes to submitting the form back to the servlet, I can send the file and any other details that I want, along with the UserId that was actually selected. </p>
  
  <p>Unfortunately the session variable always sets the userId to that of the last record. </p>
  
  <p>I'm probably doing a lot of things wrong, but I'm just confused as to how else I'd get to know what record is clicked on in the table of the web page?</p>
  
  <p>Any help is much appreciated..</p>