JSP中如何实现分页?
我有一个页面,其中显示一个表,其中包含一些条目,这些条目是第一次从 JPA 实体的列表形式的方法中获取。
现在我有 3 个按钮:上一个、接受、下一个
我想要的是当我单击下一个或上一个按钮时,它应该显示上一个/ 下一个条目。
这里有一些代码片段:
<%!
Request req=new Request();
List<pendingRequest> li= req.showDetails();
int i=0;
pendingRequest pr=null; %>
<%pr=li.get(i); %>
<table align="center">
<tr><td><b>Employee Id :</b></td><td><%=pr.getEmpId()%></td></tr>
<tr><td><b>Name :</b></td><td><%=pr.getEmpName()%></td></tr>
<tr><td><b>Phone Number :</b></td><td><%=pr.getEmpPhnNo()%></td></tr>
<tr><td><b>Email Id :</b></td><td><%=pr.getEmpEmail()%></td></tr>
<tr><td><b>Password :</b></td><td><%=pr.getEmpPassword()%></td></tr>
</table><br><br>
<table align="center">
<tr><td>
<input type="button" value="Previous" onclick="">
<input type="button" value="Accept" onclick="">
<input type="button" value="Next" onclick="">
</td></tr>
</table>
有人可以帮助我,我应该如何继续使其成为可能吗?
提前致谢。
I have a page which displays a table with some entries which is taken from a method in form of a list from a JPA Entity for the first time.
now I have 3 buttons: previous, accept, next
what I want is when I click the next or previous button, it should show the previous / next entry.
here are some code snippets:
<%!
Request req=new Request();
List<pendingRequest> li= req.showDetails();
int i=0;
pendingRequest pr=null; %>
<%pr=li.get(i); %>
<table align="center">
<tr><td><b>Employee Id :</b></td><td><%=pr.getEmpId()%></td></tr>
<tr><td><b>Name :</b></td><td><%=pr.getEmpName()%></td></tr>
<tr><td><b>Phone Number :</b></td><td><%=pr.getEmpPhnNo()%></td></tr>
<tr><td><b>Email Id :</b></td><td><%=pr.getEmpEmail()%></td></tr>
<tr><td><b>Password :</b></td><td><%=pr.getEmpPassword()%></td></tr>
</table><br><br>
<table align="center">
<tr><td>
<input type="button" value="Previous" onclick="">
<input type="button" value="Accept" onclick="">
<input type="button" value="Next" onclick="">
</td></tr>
</table>
can somebody please help me how should I proceed to make it possible?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该修改
showDetails
方法以接受两个参数:pageNumber
、resultsPerPage
。然后,在
showDetails
方法中,您将看到如下内容:在页面顶部设置页码:
更改
Next
和Previous
带链接的输入(假设您的 JSP 文件名为list.jsp
):这需要进行一些调整(例如,确保 pageNumber 永远不会小于 0),但总的来说,这是您的方法可以采取。
You should modify your
showDetails
method to accept two parameters:pageNumber
,resultsPerPage
.Then inside your
showDetails
method you'll have something like this:Set the page number at the top of the page:
Change the
Next
andPrevious
inputs with links (let's suppose your JSP file is namedlist.jsp
):This needs a little bit of tweaking (e.g. to ensure the pageNumber never becomes less than 0), but overall this is the approach you could take.
Behrang
回答的是非常棒的内在工作。或者,您可以使用 displaytag.sf.net/ 以防您可能试图重新发明轮子。 displaytag还允许用户将表格导出为pdf和excel格式,因此在某些情况下您不需要编写额外的代码来进行报告。
What
Behrang
answered is the inner-working which is fabulous.Alternatively you can use displaytag.sf.net/ in case you might be trying to reinvent the wheel. The displaytag also allows the user to export the table to pdf and excel format, so you don't need to write extra codes for reporting in some cases.