jsp 实现分页

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="java.sql.*"%>
<jsp:useBean id="menuManage" class="menu.MenuManage" scope="page" />
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>系统菜单管理</title>
<link rel="stylesheet" rev="stylesheet" href="admin.css" type="text/css" media="all" />
</head>
<%
String sqlstr="",option="",value="";
ResultSet rs = null ;
int pageSize = 4 ;//每页3行
int showPage = 1 ;//当前页次
int rowCount = 0 ;//共多少行
int pageCount = 0 ;//共多少页

option=request.getParameter("search");
value = request.getParameter("searchvalue");
//out.print(option);
//out.print(value);
if(option=="选择查询条件"||option==null||value==null||value.trim()=="")
{
sqlstr = "select m_main_kind, m_sub_kind, m_id, m_name, m_link,m_target, m_desc, m_sort,decode(stop_rmk,'N','未停用','Y','已停用','T','测试中','')   from menu order by m_main_kind,m_sub_kind,m_sort " ;
menuManage.getMenu(sqlstr);
}
else
{
sqlstr = "select m_main_kind, m_sub_kind, m_id, m_name, m_link,m_target, m_desc, m_sort,decode(stop_rmk,'N','未停用','Y','已停用','T','测试中','')   from menu where "+option+" = ?  order by m_main_kind,m_sub_kind,m_sort " ;
menuManage.getMenu(sqlstr,value.trim());
}
rs = menuManage.getResultSet();
%>

<body>
<form name="menuManageForm" action="menu_manage.jsp" method="post">
<div id="admincss">
<div id="title">系统菜单管理</div>
<table>
<thead>
<tr>
<th colspan="11" align="center">
<select name="search" size="1">
<option id="search_select" value="search_select" selected="selected">选择查询条件</option>
<option id="m_main_kind" value="m_main_kind" >主分类</option>
<option id="m_sub_kind" value="m_sub_kind" >子分类</option>
<option id="m_id" value="m_id" >菜单ID</option>
<option id="m_name" value="m_name" >菜单名称</option>
<option id="m_link" value="m_link" >链接URL</option>
<option id="m_target" value="target" >打开位置</option>
<option id="m_desc" value="menu_desc" >描述</option>
<option id="stop_rmk" value="stop_rmk" >停用</option>
</select>
<input type="text" name="searchvalue" size="16" id="searchvalue" />
<button type="submit" name="searchbtn" value="查询" />查询</button>
<button type="button" name="cleanbtn" value="清除" />清除</button>
<button type="button" name="insertbtn" value="新增" onclick="window.open('menu_insert.jsp','main');"/>新增</button>
</th>
</tr>
<tr>
<th>行号</th>
<th style="width:40px">主分类</th>
      <th style="width:40px">子分类</th>
<th>菜单ID</th>
<th>菜单名称</th>
<th>链接URL</th>
<th style="width:60px">打开位置</th>
<th>描述</th>
<th>停用</th>
<th>排序</th>
<th>编辑</th>
</tr>
</thead>
<tbody>
<%
int row = 0;
String toPage = request.getParameter("topage") ;

try
{
rs.last();
rowCount = rs.getRow();
pageCount = ((rowCount%pageSize) == 0?(rowCount/pageSize):(rowCount/pageSize)+1);

if(toPage!=null)
{
showPage = Integer.parseInt(toPage) ;
if(showPage > pageCount)
{
showPage = pageCount ;
}
else if(showPage <= 0)
{
showPage = 1 ;
}
}

//rs.beforeFirst();
rs.absolute((showPage - 1)*pageSize + 1);


for(int i=0;i<pageSize;i++)
{
row++;
out.print("<tr  onMouseMove=this.style.background=\"#dbc8ef\" onMouseOut=this.style.background=\"#eef5fb\" onmousedown=this.style.background=\"#c7e1b2\">");
out.print("<td>"+row+"</td>");
out.print("<td>"+rs.getString(1)+"</td>");//主分类
out.print("<td>"+rs.getString(2)+"</td>");//子分类
out.print("<td>"+rs.getString(3)+"</td>");//菜单ID
out.print("<td>"+rs.getString(4)+"</td>");//菜单名称
out.print("<td>"+rs.getString(5)+"</td>");//链接URL
out.print("<td>"+rs.getString(6)+"</td>");//打开位置
out.print("<td>"+rs.getString(7)+"</td>");//菜单描述
out.print("<td>"+rs.getInt(8)+"</td>");//排序
out.print("<td>"+rs.getString(9)+"</td>");//停用标记
out.print("<td><a href=\"menu_update.jsp?main_kind="+rs.getString(1)+"&sub_kind="+rs.getString(2)+"&m_id="+rs.getString(3)+"\" target=\"main\">修改</a>|<a href=\"menu_update_result.jsp?main_kind="+rs.getString(1)+"&sub_kind="+rs.getString(2)+"&m_id="+rs.getString(3)+" &update_kind=d\" target=\"main\">删除</a>");
out.print("</tr>");
if(!rs.next())
{
break ;
}
}
}
catch(SQLException sqle)
{
out.print("读取菜单出错="+sqle);
}
finally
{
rs.close();
}
%>
</tbody>
<tfoot>
<tr>
<td colspan="11" align="center"><font color="#0cfd06" size="2px"><a href=menu_manage.jsp?topage=<%=1 %> name="pre_page">第一页</a> <a href=menu_manage.jsp?topage=<%=showPage - 1 %> name="pre_page">上一页</a>[共:<%=pageCount %>页,当前页第<%=showPage %>页,每页<%=pageSize %>行,共:<%= rowCount %>行]<a href="menu_manage.jsp?topage=<%=showPage + 1 %>" name="next_page">下一页</a> <a href=menu_manage.jsp?topage=<%=pageCount %> name="pre_page">最末页</a></font>
<!-- 
<button type="button" name="prepage" id="prepage" value="上一页"/>上一页</button>
<button type="button" name="nextpage" id="nextpage" value="下一页"/>下一页</button>
<button type="button" name="insert" id="insert" value="新增"/>新增</button>
<button type="button" name="update" id="update" value="修改"/>修改</button>
<button type="button" name="delete" id="delete" value="删除"/>删除</button>
-->
</td>
</tr>
</tfoot>
</table>
<div id="foot"><a href=system_manage.jsp target="main">返回</a></div>
</div>
</form>
</body>
</html>

你可能感兴趣的:(html,sql,jsp)