JSP中的表格是通过插入<table>标签实现的。
<html>
<body>
<table border="1">
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
</table>
</body>
</html>
运行结果:
jsp页面可以用分页来控制查询到的多条数据。
具体实例如下:
public class PageResult {
private List list; //装分页列表中的内容
private Integer firstPage; //第一页
private Integer prePage; //上一页
private Integer nextPage;//下一页
private Integer currentPage;//当前页面
private Integer totalPage; //总页数/尾页
private Integer count;//总条数
private Integer size; //每页多少条
public List getList() {
return list;
}
public void setList(List list) {
thislist = list;
}
public Integer getFirstPage() {
return firstPage;
}
public void setFirstPage(Integer firstPage) {
thisfirstPage = firstPage;
}
public Integer getPrePage() {
return (thiscurrentPage-1==01:thiscurrentPage-1);
}
public void setPrePage(Integer prePage) {
thisprePage = prePage;
}
public Integer getNextPage() {
return (thiscurrentPage==thistotalPagethistotalPage:thiscurrentPage+1);
}
public void setNextPage(Integer nextPage) {
thisnextPage = nextPage;
}
public Integer getCurrentPage() {
return currentPage;
}
public void setCurrentPage(Integer currentPage) {
thiscurrentPage = currentPage;
}
public Integer getTotalPage() {
return (thiscount%thissize==0thiscount/thissize:thiscount/thissize+1);
}
public void setTotalPage(Integer totalPage) {
thistotalPage = totalPage;
}
public Integer getCount() {
return count;
}
public void setCount(Integer count) {
thiscount = count;
}
public Integer getSize() {
return size;
}
public void setSize(Integer size) {
thissize = size;
}
}
public class listServlet extends HttpServlet {
private IProductDAO dao;
@Override
public void init() throws ServletException {
dao = new IProductDAOImpl();
superinit();
}
<title>货品列表</title>
</head>
<body>
<form action="/list" method="post">
<table border="1">
<tr>
<td>货品名称</td>
<td><input type="text" name="productName"></td>
</tr>
<tr>
<td>品牌</td>
<td><input type="text" name="brand"></td>
</tr>
<tr>
<td>零售价</td>
<td><input type="text" name="salePrice"></td>
</tr>
<tr align="center">
<td colspan="2"><input type="submit" value="查询"></td>
</tr>
</table>
</form>
<table border="1">
<tr>
<th>货品</th>
<th>零售价</th>
<th>品牌</th>
<th>折扣</th>
<th>供应商</th>
<th> *** 作</th>
</tr>
<c:forEach items="${pageResultlist}" var="product">
<tr>
<td>${productproductName}</td>
<td>${productsalePrice}</td>
<td>${productbrand}</td>
<td>${productcutoff}</td>
<td>${productsupplier}</td>
<td><a href='/employeecmd=remove&id=${employeeid}'>删除</a> <a href='/employeecmd=edit&id=${employeeid}'>修改</a></td>
</tr>
</c:forEach>
<tr>
<th><a href="/listcurrentPage=${pageResultfirstPage}">首页</a>${pageResultfirstPage}</th>
<th><a href="/listcurrentPage=${pageResultprePage}">上一页</a>${pageResultprePage}</th>
<th><a href="/listcurrentPage=${pageResultnextPage}">下一页</a>${pageResultnextPage}</th>
<th><a href="/listcurrentPage=${pageResulttotalPage}">尾页</a>${pageResulttotalPage}</th>
<th>当前${pageResultcurrentPage}/${pageResulttotalPage}页</th>
<th>总条数:${pageResultcount}</th>
</tr>
</table>
</body>
</html>
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String currentPage = requestgetParameter("currentPage");
PageResult pageResult = new PageResult();
if(StringUtilsisBlank(currentPage))
{
currentPage="1";
}
pageResultsetCurrentPage(IntegerparseInt(currentPage));
pageResultsetSize(5);
List<Product> list = daolist(pageResultgetCurrentPage(), pageResultgetSize());
pageResultsetList(list);
int count = daocount();
pageResultsetCount(count);
//如果当前页等于第一页,则上一页就是第一页,否则为当前页上一页
pageResultsetPrePage(pageResultgetPrePage());
//如果当前页是尾页,则下一页就是尾页,否则为当前页的下一页
pageResultsetNextPage(pageResultgetNextPage());
pageResultsetCount(count);
pageResultsetTotalPage(pageResultgetTotalPage());
requestsetAttribute("pageResult", pageResult);
requestgetRequestDispatcher("/listjsp")forward(request, response);
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)