-1

我正在开发分类网站。在广告视图页面中,我必须从数据库获取广告数据。所以我用servlet来做。现在所有的工作都已经完成并且工作完美。但毕竟它看起来很基本(我的意思是没有吸引力。)。我想让它看起来很专业。我是怎么做到的?请帮我看看这个专业。谢谢你。迪尔山。

Servlet 代码是这样的:

    int page = 1;
    int recordsPerPage = 5;
    if(request.getParameter("page") != null)
    page = Integer.parseInt(request.getParameter("page"));
    //  EmployeeDAO dao = new EmployeeDAO();
    View_ads_cls be=new View_ads_cls();
    List<Ads_view_to> list = be.getRecentAdd((page-1)*recordsPerPage,
    recordsPerPage);
    int noOfRecords = be.getNoOfRecords();
    int noOfPages = (int) Math.ceil(noOfRecords * 1.0 / recordsPerPage);
    request.setAttribute("allads", list);
    request.setAttribute("noOfPages", noOfPages);
    request.setAttribute("currentPage", page);
    RequestDispatcher view = request.getRequestDispatcher("ad_viewer.jsp");
    view.forward(request, response);     

jsp 页面在这里: Emp ID Emp Name Salary Dept Name Dept Name2

    <c:forEach var="employee" items="${allads}">
    <tr>
    <td>${employee.brand}</td>
    <td>${employee.description}</td>
    <td>${employee.price}</td>
     <td><img src=${employee.imageurl}></td>


 </tr>
 </c:forEach>
 </table>
<c:if test="${currentPage != 1}">
<td><a href="view_ads?page=${currentPage - 1}">Previous</a></td>
</c:if>

<%--For displaying Page numbers.
The when condition does not display a link for the current page--%>
<table border="1" cellpadding="5" cellspacing="5">
    <tr>
<c:forEach begin="1" end="${noOfPages}" var="i">
<c:choose>
<c:when test="${currentPage eq i}">
<td>${i}</td>
</c:when>
<c:otherwise>
 <td><a href="view_ads?page=${i}">${i}</a></td>
 </c:otherwise>
</c:choose>
</c:forEach>
</tr>
</table>

<%--For displaying Next link --%>
<c:if test="${currentPage lt noOfPages}">
<td><a href="view_ads?page=${currentPage + 1}">Next</a></td>
</c:if>
4

1 回答 1

0

查看以下链接 link1Link2Link3。您必须花时间使用搜索引擎来找出适合您的分页。

于 2013-09-30T17:59:37.393 回答