jsp fenye_easy

<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%! String aTitle,aAuthor,AType,ArticleType,InsertTime,Color; %>





























<% int i; int ipage=10; //分页单位 int allpage; //总页数 int pages; //接受的页码变量 int cpage=1; //当前页 int spage; //开始页 //数据库连接声明 java.lang.String sql,pagesql; java.sql.ResultSet rs,pagers; pagesql = "select count(a_id) as A from article"; //取总文章数 pagers = sqlconn.executeQuery(pagesql); int allCol = pagers.getInt("A"); //获得总页面数 allpage = (int)Math.ceil((allCol + ipage-1) / ipage); //判断参数pages是否为空 if (request.getParameter("pages")==null) { pages=1; } else { pages = new Integer(request.getParameter("pages")).intValue(); } //判断当前页 if(pages > allpage || pages == 0){
cpage = 1;
} else {
cpage = pages;
}

//判断起始页
spage=(cpage-1)*ipage;

sql = "select a_id,a_title,a_author,aID,a_time,a_readtime,sID from article order by a_id desc limit "+ spage +","+ ipage;
rs = sqlconn.executeQuery(sql);
int cu=1;

//循环取数据库值
while (rs.next()) {
int aID = rs.getInt("a_id");
aTitle = rs.getString("a_title");
aAuthor = rs.getString("a_author");
int ArticleTypeID = rs.getInt("aID");
int ReadTime = rs.getInt("a_readtime");
InsertTime = rs.getString("a_time");
if (cu % 2 == 0) { Color="#DBECFD"; }
else { Color="#C6E1FD"; }
switch (ArticleTypeID) {
case(1):
ArticleType="小说";
break;
case(2):
ArticleType="散文";
break;
case(3):
ArticleType="诗歌";
break;
case(4):
ArticleType="随笔";
break;
}
%>
">






<% cu++; } %>



标题 作者 类型 点击 加入时间
"><%= aTitle %> <%= aAuthor %> <%= ArticleType %> <%= ReadTime %> <%= InsertTime %>
共 <%= allCol %>条记录 共 <%= allpage %>页
<% if (cpage>1) { %>
">
<% } if (cpage
">
<% } %>
/
<% for (i=1;i<=allpage;i++) { if (i != pages) {%>
"><%= i %>
<% } }%>

0 Comments:

Post a Comment



 
Copyright 2005-2007. Hello Wiki designed by Fen, Blogger Templates by Blogcrowds.