一聚教程网:一个值得你收藏的教程网站

最新下载

jsp分页程序代码

时间:2009-09-11 00:00:00 编辑:简简单单 来源:转载

jsp分页程序代码
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@include file ="../inc/ChkPwd.jsp"%>
<%@include file="../DB.jsp"%>
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
http://www.w3.org/1999/xhtml">



文章管理

 


 
     
 
 
 
 
 
 
         
<%
String op;
String ID = request.getParameter("id");
op = request.getParameter("op");
if(op==null){
 op = "my";
}
if (op.equals("del") && ID!=null){
 String bbb = new String(request.getParameter("BigClassName").getBytes("iso8859_1"));
 Statement stmt_ChannelDEL=conn.createStatement();
 String Sqldel="delete from hl_news where id=" + ID;
 int shan=stmt_ChannelDEL.executeUpdate(Sqldel);
 if (shan>0)
 {
  out.print("<script type="text/javascript"> alert("已成功删除!"); window.location.href='Hanye_Manages.jsp?BigClassName="+bbb+"'; </script>"); 
 }
 stmt_ChannelDEL.close();
 return ;
}
 Statement stmtA=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
 String SqlA="Select * from hl_smallclass WHERE bigname='行业新闻' order by id asc";
 ResultSet RsA=stmtA.executeQuery(SqlA);
 while (RsA.next()) {
  
%>
          <%=RsA.getString("smallname")%> |
<%
}
 RsA.close(); //关闭记录集对象
 stmtA.close(); //关闭语句对象
%>   

       

       



 
   
 
--内容管理

 

     

       
  
           
   
   
   
    
      
           
   
    
   
   
   
   
         
<%
int pageSize=10;  //每页显示的文章数
int showPage=1;   //当前页面显示的页号
int recCount=0;   //ResultSet中的文章总数
int pageCount=0;  //分页后的总页数
String SqlArticle;

String toPage = request.getParameter("page");
String bgname = new String(request.getParameter("BigClassName").getBytes("iso8859_1"));
Statement stmt_Article=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
SqlArticle="Select * from hl_news where smallname='"+bgname+"' order by ID DESC";
ResultSet RsArticle=stmt_Article.executeQuery(SqlArticle);

 if(RsArticle.next()) {
 RsArticle.last();//指针飞到最后
 recCount=RsArticle.getRow();//去除最后一行的行号
 pageCount=((recCount%pageSize)==0?(recCount/pageSize):(recCount/pageSize)+1);//得到一共可以分多少页
 if(toPage!=null)
  showPage=Integer.parseInt(toPage);
  RsArticle.absolute((showPage-1)*pageSize+1);//跳到第showpage页的第一条
 for(int i=1;i<=pageSize;i++){
  int NID=RsArticle.getInt("ID");
  String img = RsArticle.getString("img");
  String ttt = RsArticle.getString("times");
  //ttt=ttt.substring(0,10);
 %>   
   


           
   
           
   
           
   
   
   
   
   
           
   
           
         
<%
 if(!RsArticle.next())
  break;
 }
}
%>      

     

   
     

     

ID新闻大类新闻小类新闻标题新闻图片发布时间操作
<%=NID%><%=RsArticle.getString("bigname")%><%=RsArticle.getString("smallname")%><%=RsArticle.getString("Title")%><%=img%><%=ttt%>修改|删除

       
         
   
         
       
     

   
        
        
  
     
     

     
        共<%=pageCount%>页 <%  for(int i=1;i<=pageCount;i++){  %> <% if(i==showPage){ %><%=i %><% }else{ %>[<%=i %>] <% } } %>
          

  

 

 
     
       
     
   
查询:
         
                 

 
 
   


<%
RsArticle.close();
stmt_Article.close();
conn.close();
%>

文章评论

热门栏目