Home Ask Login Register

Developers Planet

Your answer is one click away!

Joe February 2016

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

I have a html table in my jasp that presenting pairs of id & month, it looks like this:

enter image description here

the jsp looks like 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>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <form method="Post" action="payCheckInfo">
            <table id="ptable" border="1">

                    <td style="text-align: center;">ID</td>
                    <td style="text-align: center;">Month</td>

                <c:forEach var="entry" items="${EmployeeHashMap}" >
                    <!-- entry.key is employee.key -->
                    <!-- entry.value is employee.skills -->
                    <c:forEach var="month" items="${entry.value}" >
                            <td><a href="payCheckInfo">${entry.key}</a></td>

</html>Type a message

Now I want that every time that a user will click on some id (which is a link) I will go to payCheckInfo which is my servlet and from there I can get to the specific row data, cause in payCheckInfo I have a method that is doing what I need to do with the data


Satya February 2016

Get specific row data of a row.

$("tr.table").click(function() {
    var tableData = $(this).children("td").map(function() {
        return $(this).text();

    alert($.trim(tableData[0]) + " , " + $.trim(tableData[1]));
    //Here, Make a Ajax call to your Servlet payCheckInfo 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
           <tr class="table">
                <td class="table">
            <tr class="table">
                <td class="table">

Post Status

Asked in February 2016
Viewed 2,672 times
Voted 10
Answered 1 times


Leave an answer

Quote of the day: live life