我正在开发机密网站。在广告查看页面中,我必须从数据库获取广告数据。所以我用servlet来做。现在所有工作都已完成并且工作完美。但毕竟它看起来很基本(我的意思是没有吸引力)。我想让它看起来很专业。我是怎么做到的?请帮我看看这个专业人士。 谢谢。 Dilshan。
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名称 薪水 部门名称 部门名称2
<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>