我在使用Java。
这里是我的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>这是我的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>我使用以下方法在servlet中获得复选框值:
String checkboxValues[] = request.getParameterValues("selectedCategory");我在JSP中使用datatable。我的问题是,如果JSP显示的页面超过1页,并且从这些页面中选择了一些行,那么servlet只能从显示的页面中获取值。如何从servlet中获取所有选定的值?如果我使用checkall复选框,如何从servlet中获取所有值?
发布于 2015-05-19 07:56:35
JSP是一种非常简单的技术。在JSP中完成的任何服务器端分页通常都由程序员管理。JSP不会帮助您分页。
通常,程序员需要精心编排才能使分页工作(比如传递参数(如currentPage、totalPages、rowsPerPage等),然后过滤将显示在页面上的少数行。它们还为页码提供超链接,为上一页和下一页链接提供更多的超链接)。
从您共享的代码片段中,看起来显示了categoryList中的所有行。如果categoryList有1000行,则所有1000行都将显示在同一页中。
要使分页工作,应该有一些servlet或struts Action来管理categoryList。只应将与当前页码相关的少数行加载到该数组列表中。
考虑到所有这些,您可以理解,即使是'check- all‘之类的东西也必须由开发人员使用相当多的代码来管理。。
每当用户单击以从页面导航时,您可能必须将与所选复选框对应的类别ids附加到下一页的URL中,然后在服务器上维护所选类别ids的数组列表。如果用户执行新的搜索等等,则还必须清除此列表。
https://stackoverflow.com/questions/30319374
复制相似问题