java - How to pass table row data to a servlet from the jsp? -


i have html table in jasp presenting pairs of id & month, looks this:

enter image description here

the jsp looks this:

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@page import="java.util.map"%> <%@page import="java.util.list"%> <%@page contenttype="text/html" pageencoding="utf-8"%> <!doctype html> <html>     <head>         <meta http-equiv="content-type" content="text/html; charset=utf-8">         <title>jsp page</title>     </head>     <body>         <form method="post" action="paycheckinfo">             <table id="ptable" border="1">                  <tr>                     <td style="text-align: center;">id</td>                     <td style="text-align: center;">month</td>                 </tr>                    <c:foreach var="entry" items="${employeehashmap}" >                     <!-- entry.key employee.key -->                     <!-- entry.value employee.skills -->                     <c:foreach var="month" items="${entry.value}" >                         <tr>                             <td><a href="paycheckinfo">${entry.key}</a></td>                             <td>${month}</td>                         </tr>                     </c:foreach>                 </c:foreach>              </table>         </form>     </body> </html>type message 

now want every time user click on id (which link) go paycheckinfo servlet , there can specific row data, cause in paycheckinfo have method doing need data

get specific row data of row.

$("tr.table").click(function() {      var tabledata = $(this).children("td").map(function() {          return $(this).text();      }).get();        alert($.trim(tabledata[0]) + " , " + $.trim(tabledata[1]));      //here, make ajax call servlet paycheckinfo   });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <table>             <tr class="table">                  <td class="table">                       id1                  </td>                  <td>                      month1                  </td>              </tr>              <tr class="table">                  <td class="table">                       id2                  </td>                  <td>                      month2                  </td>              </tr>  </table>


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -