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+"/";

%>


<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">
    
    <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 list=new ArrayList(); 
    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">  
                 <a href="<%=path %>/dao/News_servlet?method=delete&&ID=<%=(list.get(count+1).getT_ID())%>">
                              删除a>      
                 <a href="<%=path %>/news_type/add.jsp">
                              添加a>      
                 <a href="<%=path %>/dao/News_servlet?method=update&&ID=<%=(list.get(count+1).getT_ID())%>">
                              修改a>      
                 <a href="<%=path %>/dao/News_servlet?method=detail&&ID=<%=(list.get(count+1).getT_ID())%>">
                              详情a>  td>
                 <% count++; %> 
                 tr>
           c:forEach> 
        <%--   <% page_size=page_count+page_size;   %> --%>
                 <tr>
                   <td colspan="2" align="right"> 本页总共<%=count%>条           总共<%=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分页代码以及效果新闻发布系统_第1张图片

JSP分页c:foreach分页代码以及效果新闻发布系统_第2张图片
JSP分页c:foreach分页代码以及效果新闻发布系统_第3张图片

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

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

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

你可能感兴趣的:(JavaWeb)