我们实训周做了一个新闻发布系统,也就是今天2015年10月10号周六,刚过完国庆,今天加课,我做了新闻类别的增删改查,耗费了俩个小时做出来了分页,值得让我记录一下,挺费劲的

下面是实现的JSP用到c: foreach的标签库结构实现分页

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page language="java" import="bean.*" %>
<%@ page language="java" import="dal.*" %>
<%@ page language="java" import="dao.*" %>
<%@ page language="java" import="util.*" %>
<%@ page language="java" import="java.io.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>
<!-- 测试的网址是: http://localhost:8080/News_release_system/news_type/test.jsp -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>类别新闻 的增删改查</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<style type="text/css" >
body{
text-align: center;
}
table{
text-align:center;
border-collapse:collapse;
}
.font{
font-family:"华文新魏";
font-size: 18px;

}
</style>

</head>

<body class="font">
<% ArrayList<NRC_TYPE> list=new ArrayList<NRC_TYPE>();
News_type_Dao type=new News_type_Dao();
NRC_TYPE typebean=new NRC_TYPE();
list=type.queryall();
pageContext.setAttribute("list", list);
int count=0; //总行数
int page_count=1; //开始条数
int page_total=1; //,总页码
int page_current= 1; //首页
int page_size=20;//一页的行数
%>

<br><h1>类别新闻</h1>

<%
String page_cu = request.getParameter("page_current");
if(page_cu==null){
page_cu="1";
}
page_current = Integer.parseInt(page_cu);
if(page_current<0){
page_current = 1;
}
page_count=page_count+ page_current*page_size;

%>
<table align="center" width="100%" border="3px" bordercolor="#OOO" cellspacing="5px">
<tr>
<th >新闻类别序号</th>
<th>新闻类别名称</th>
<th>新闻类别详述</th>
<th nowrap="nowrap">新闻类别具体操作</th>
</tr>
<c:forEach items="${list}" var="typebean" step="1" varStatus="i"
begin="<%=page_count%>" end="<%=page_size+page_count-1%>">
<tr>
<td>${i.index}</td>
<td>${typebean.getT_NAME()}</td>
<td>${typebean.getT_MEMO()}</td>
<td nowrap="nowrap">&nbsp;&nbsp;
<a href="<%=path %>/dao/News_servlet?method=delete&&ID=<%=(list.get(count+1).getT_ID())%>">
删除</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="<%=path %>/news_type/add.jsp">
添加</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="<%=path %>/dao/News_servlet?method=update&&ID=<%=(list.get(count+1).getT_ID())%>">
修改</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="<%=path %>/dao/News_servlet?method=detail&&ID=<%=(list.get(count+1).getT_ID())%>">
详情</a>&nbsp;&nbsp;</td>
<% count++; %>
</tr>
</c:forEach>
<%-- <% page_size=page_count+page_size; %> --%>
<tr>
<td colspan="2" align="right"> 本页总共<%=count%>条 &nbsp; &nbsp; &nbsp; &nbsp; 总共<%=list.size()%>条</td>
<%
page_total = ((list.size())%20==0)?((list.size())/20):((list.size())/20+1);

%>
<td colspan="2" align="center">

<a href = "page.jsp?page_current=1" >首页</a>
<a href = "page.jsp?page_current=<%=page_current-1%>" >上一页</a>
<a href = "page.jsp?page_current=<%=page_current+1%>" >下一页</a>
<a href = "page.jsp?page_current=<%=page_total%>" >尾页</a>
第<%=page_current+1%> 页/共 <%=page_total%>页
</td>
</tr>

<%-- <% if(count==0){
request.getRequestDispatcher("/news_type/test.jsp").forward(request, response);
}
%>
--%>

</table>


</body>
</html>

JSP分页c:foreach分页代码以及效果新闻发布系统_发布

JSP分页c:foreach分页代码以及效果新闻发布系统_分页_02

JSP分页c:foreach分页代码以及效果新闻发布系统_JAVAweb_03

所有源码都凡在,大家可以学习一下,JAVAweb

项目

还有一些JSP和html的参考样式在

http://jingyan.baidu.com/article/466506583bfc5ef549e5f835.html

http://jingyan.baidu.com/article/6b182309ad16b9ba58e15933.html