getting value of selected checkbox from datatable in jsp

i’m using java ee,
here my jsp:

<form  method="POST" enctype="multipart/form-data"action="<c:url value="submitSelected"/>">
<div class="box-body">
    <table id="example" class="table table-bordered table-striped">
        <thead>
            <tr>
                <th>id</th>
                <th>name</th>
                <th><input type="checkbox" id="checkall" /></th>
            </tr>
        </thead>
        <tbody>
            <c:forEach var="category" items="${categoryList}">
                <tr>
                    <td><c:out value="${category.id}"/></td>
                    <td><c:out value="${category.name}"/></td>
                    <td><input type="checkbox" name="selectedCategory" value="${category.id}" /></td>
                </tr>                           
            </c:forEach>
        </table>
    </div>
    <div class="box-footer" id="hidden-div">
        <button type="submit" id="select" >submit</button>
    </div></form>

here my js :

<script type="text/javascript">
$(document).ready(function () {
    $("#example").dataTable({
        "scrollX": true
    });
    $("#example #checkall").click(function () {
        if ($("#example #checkall").is(':checked')) {
            $("#example input[type=checkbox]").each(function () {
                $(this).prop("checked", true);
            });

        } else {
            $("#example input[type=checkbox]").each(function () {
                $(this).prop("checked", false);
            });
        }
    });
});</script>

i get my checkbox values in my servlet using:

String checkboxValues[] = request.getParameterValues("selectedCategory");

im using datatable in my jsp, my question is if my jsp display more than 1 page and i select some rows from those page, my servlet only get values only from displayed page. how to get all the selected value from servlet? and if i use the checkall checkbox, how to get all value from servlet?
thanks and sorry for my bad english


Source: jsp

Leave a Reply