栏目列表前台分页

23 篇文章 0 订阅

栏目列表前台分页:数据结构上是用户自定义分页符号,见到这个分页符号就自动分页。
IP地址最后三位替换为*了。
<?xml version="1.0" encoding="gb2312"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<%@ page contentType="text/vnd.wap.wml;charset=gb2312"%>
<%@ include file="/common/link.inc"%>
<%@ page import = "java.util.*"%>
<%@ page import = "java.util.HashMap"%>
<%@ include file="toUTF.jsp"%>
<%@ page import="java.sql.*"%>
<%
    Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
    Statement stmtHref=con.createStatement();
    ResultSet rs = null,rsHref = null;

    int type = 0,id = 0,loc_id = 0;
    int parentId = 0;
    String name="",pic_path="",link_url="";
    String href = "#";
    String sqlHref = "";
    String kindId = request.getParameter("id");

    int tmpKindId;
    if(kindId == null)    {tmpKindId = 0;}
    else {tmpKindId = Integer.parseInt(kindId);}

    String sql="";
//父id
    sql = " select parent_id"
        + " from life_kind where id = " + tmpKindId
        + " order by loc_id";
    rs = stmt.executeQuery(sql);
    if(rs.next())
    {
        parentId = rs.getInt(1);
    }
//分页 type = 6
    Map beginMap = new HashMap();
    Map endMap = new HashMap();
    String tmpId = "0";
    sql = " select loc_id"
        + " from life_kind where parent_id = " + tmpKindId + " and type = 6"
        + " order by loc_id";
    rs = stmt.executeQuery(sql);
    int pNum = 1;
    while(rs.next())
    {
        beginMap.put(""+pNum,tmpId);
        tmpId = rs.getString(1);
        endMap.put(""+pNum,tmpId);
        pNum++;
    }
 String testSql=sql;
//  当前页数pNumNow
    String pNum1=request.getParameter("pNum");
    String sqlSub="";
    int pNumNow = 0;
    if(pNum1 !=null)  //生成分页后条件sql语句
    {
        pNumNow = Integer.parseInt(pNum1);
    }
 else
 {
  pNum1 = "1";
  pNumNow = 1;
 }
        if((pNum > 1)&&(pNumNow == pNum))//有分页符号且是最后一页
        {//
            pNum1 = "" + (pNum - 1);
            sqlSub = " and loc_id > " + Integer.parseInt((String)endMap.get(pNum1));
        }
        else if ((pNum > 1)&&(pNumNow == pNum))//有分页符号且是第一页
        {
            sqlSub = " and loc_id < " + Integer.parseInt((String)beginMap.get(pNum1));
        }
        else if (pNum > 1)
        {
        sqlSub = " and loc_id > " + Integer.parseInt((String)beginMap.get(pNum1));
        sqlSub += " and loc_id < " + Integer.parseInt((String)endMap.get(pNum1));
        }


    sql = " select id,name,type,loc_id,pic_path,link_url,create_date"
        + " from life_kind where parent_id = " + tmpKindId
  +  sqlSub
        + " order by loc_id";
    rs = stmt.executeQuery(sql);
%>
<wml>
<card  title="MOA_kind" id ="MOA">
<p>
<%while(rs.next())
{
    pic_path = "";
    id = rs.getInt(1);
    name = rs.getString(2);
    type = rs.getInt(3);
    loc_id = rs.getInt(4);
    pic_path = rs.getString(5);
    link_url = rs.getString(6);
    if(pic_path != null)
    {
        pic_path = "<img src=/"/images/"+pic_path+"/" alt='' />";
    }
    switch(type)
    {
//0    有子类    点击进入子类名称列表
        case 0:
             href = pic_path + "<a href=/"http://61.136.114.*/kind.jsp?id=" + id + "/">" + name + "</a>";
        break;
//1    无子类有标题    点击分类名称进入内容标题列表页面
        case 1:
             href = pic_path + "<a href=/"http://61.136.114.*/title.jsp?kindId=" + id + "/">" + name + "</a>";
        break;
//2    无子类无标题    点击分类名称进入直接显示内容表关联此kind_id的信息.如果是此类型的话,只能在内容表一篇无标题的信息
        case 2:
             href =  pic_path + "<a href=/"http://61.136.114.*/detail.jsp?kindId=" + id + "/">" + name + "</a>";
        break;
//3    动态栏目链接    本身就是一动态栏目的链接。链接地址存入life_kind.Link_url
        case 3:
             href =  pic_path + " <a href=/"" + link_url + "/">" + name + "</a>";
        break;
//4    本身是描述    则不能存储此分类的log图片,本身是一段描述性信息,在life_kind_desc表中
        case 4:
        sqlHref = " select kind_desc from life_kind_desc where kind_id = '" + id + "'";
        rsHref = stmtHref.executeQuery(sqlHref);
        if(rsHref.next())
        {
            href = rsHref.getString(1);
        }
        break;
//5    本身是图片    则不能存储此分类的log图片,本身图片地址插入life_kind.Pic_path
        case 5:
             href = pic_path;
        break;
//6    分页符号    则不能存储此分类的log图片,分类列表程序判断,如果遇到分页符号则自动到此分页
        case 6:
             href = "--------";
        break;
        default :
            href = "";
            break;
    }
%>
<%=href%><br />
<%
}
%>
<%
//分页实现
//向前翻页
if(pNum>1)
{
 if(pNumNow>1)
 {
  out.println("<a href=/"http://61.136.114.*/kind.jsp?id=" + tmpKindId + "&pNum=" +(pNumNow-1)+"/">《</a>");
 }

}
//页数字符
for (int i = 1; i <= pNum;i++)
{
 if(pNumNow == i)
 {
  out.println(i);
 }
 else
 {
  out.println("<a href=/"http://61.136.114.*/kind.jsp?id=" + tmpKindId + "&pNum=" +i+"/">"+i+"</a>");
 }
}
//向后翻页
if(pNum > 1)
{
 if(pNumNow < pNum)
 {
  out.println("<a href=/"http://61.136.114.*/kind.jsp?id=" + tmpKindId + "&pNum=" +(pNumNow+1)+"/">》</a>");
 }

}
%>
<br />
--------
<br/>
<a href="http://61.136.114.*/kind.jsp?id=<%=parentId%>" title="返回上一级">返回上一级</a>
<br/>
<a href="http://wap.monternet.com" title="移动梦网">移动梦网</a>
</p>
</card>
</wml>
<%
    rs.close();
    stmt.close();
    con.close();
%>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值