使用servlet-hibernateintegration的分页概念。 [英] Pagination concept using servlet-hibernateintegration.
本文介绍了使用servlet-hibernateintegration的分页概念。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
@WebServlet("/PagenationServlet")
public class PagenationServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
int pageNo=Integer.parseInt(request.getParameter("pageNo"));
int startIndex=pageNo*3-3;
IEmpDao dao=new EmpDaoImpl();
List lt=dao.readEmps(startIndex);
out.println("<center> ");
out.println("");
out.println("");
out.println("");
Iterator it=lt.iterator();
while(it.hasNext())
{
Employee e=(Employee)it.next();
out.println("");
out.println("");
out.println("");
out.println("");
out.println("");
}
out.println("<table border="1"><tbody><tr><th>EMPNO</th> <th>ENAME</th> <th>SAL</th> <th>DEPTNO</th></tr><tr><td>"+e.getEmpNo()+"</td><td>"+e.getEName()+"</td><td>"+e.getSalary());
out.println("</td><td>"+e.getDeptNum()+"</td></tr></tbody></table>");
long totalRows =dao.getNoOfRows();
long noOfPages =totalRows/3;
if(totalRows%3!=0)
{
noOfPages++;
}
if(pageNo==1)
{
int x=pageNo+1;
out.println("<a href=./PagenationServlet?pageNo="+x+"> Next");
}
else if(pageNo==noOfPages)
{
int x=pageNo-1;
out.println("<a href=./PagenationServlet?pageNo="+x+"> Prev");
}
else
{
int x=pageNo+1;
out.println("<a href=./PagenationServlet?pageNo="+x+"> Next");
int y=pageNo+1;
out.println("<a href=./PagenationServlet?pageNo="+y+"> Next");
}
}
}
我尝试过:
我正在尝试使用Servlet-HibernateIntegration执行与分页概念相关的程序。但是当我执行程序时,我收到的错误名为 NumberFormatException
推荐答案
试试这个代码< br $>
try this code
int pageNo = 1;
if (request.getParameter("pageNo") != null) {
pageNo = Integer.parseInt(request.getParameter("pageNo"));
}
而不是
int pageNo=Integer.parseInt(request.getParameter("pageNo"));
引起错误的原因是,当你的servlet加载时没有页面没有值
varialble
Error is caused due to at first when your servlet load there is no value for pageNo
varialble
这篇关于使用servlet-hibernateintegration的分页概念。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文