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

我们实训周做了一个新闻发布系统,也就是今天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>

效果一

效果二
分页三

所有源码都凡在,大家可以学习一下,JAVAweb
项目
http://download.csdn.net/detail/u011488009/9169253

还有一些JSP和html的参考样式在
http://jingyan.baidu.com/article/466506583bfc5ef549e5f835.html

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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

苦思冥想行则将至

穷,有钱的大爷上个两分钱吧

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值