jsp文件写分页显示

<%@ page language=“java” contentType=“text/html; charset=UTF-8”
pageEncoding=“UTF-8”%>
<%@ page import=“java.sql.*” %>

<%!
int getNewsCount(String lx){
int returnvalue=0;
try{
Class.forName(“com.mysql.jdbc.Driver”);
Connection conn=DriverManager.getConnection(“jdbc:mysql://localhost:3306/museum?user=root&password=419111&characterEncoding=utf-8”);
Statement stmt=conn.createStatement();
String strSql;
if(lx.equals(“内容列表”)){
strSql=“select count(id) xwts from userinfo;”;
}
else
{
strSql=“select count(id) xwts from userinfo where name=’”+lx+"’;";
}

	ResultSet rs=stmt.executeQuery(strSql);
	if(rs.next()){
		returnvalue=rs.getInt("xwts");
	}
	rs.close();
	stmt.close();
	conn.close();
}
catch(Exception ex){
	
}
return returnvalue;

}

%>
<%
request.setCharacterEncoding(“utf-8”);
%>

用户信息管理

<%
String strLx=request.getParameter(“list”);
if(strLx==null) strLx=“内容列表”;
%>

<%
String strSql=“select * from userinfo”;

/* if(strLx.equals(“内容列表”)){
strSql=strSql+" order by id desc";
}
else
{
strSql=strSql+" where leixing=’"+strLx+"’ order by shijian desc";
} */

int pagesize=20;
String strPage=request.getParameter(“page”);
if(strPage==null) strPage=“0”;
int curpage=Integer.parseInt(strPage);
if(curpage<1) curpage=1;

int startRow=0;
startRow=(curpage-1)*pagesize;
int total=getNewsCount(strLx);
int totalpage=0;
if(total%pagesize==0){
totalpage=total/pagesize;
}
else
{
totalpage=total/pagesize+1;
}
if(curpage>totalpage) curpage=totalpage;
int prePage=curpage-1;
if(prePage<=0) prePage=1;
int nextPage=curpage+1;
if(nextPage>totalpage) nextPage=totalpage;

try{
Class.forName(“com.mysql.jdbc.Driver”);
Connection conn=DriverManager.getConnection(“jdbc:mysql://localhost:3306/museum?user=root&password=419111&characterEncoding=utf-8”);
Statement stmt=conn.createStatement();
strSql=strSql+" LIMIT “+startRow+”,"+pagesize+";";
ResultSet rs=stmt.executeQuery(strSql);
rs.beforeFirst();
%>

<% while(rs.next()){ %>
	<tr >
	<td style="align:center"><%=rs.getString("id") %></td>
	<td>
	
	<%=rs.getString("username") %>
	
	</td>
	<td ><%=rs.getString("password") %></td>
	<td ><%=rs.getString("phone") %></td>
	<td ><%=rs.getString("name") %></td>
	<td ><%=rs.getString("idnumber") %></td>
	<td ><%=rs.getString("email") %></td>
	<td><a href="usermanagementdel.jsp?id=<%=rs.getString("id") %>" onclick="return confirm('您确定要删除吗?');">删除</a></td>

	</tr>
	</div>
id用户名用户密码用户电话用户姓名用户身份证号码用户邮箱信息删除

<%
}
%>

<%
rs.close();
stmt.close();
conn.close();
}
catch(Exception ex){
out.print(ex.getMessage());
}
%>

<div >每页<%=pagesize%>条,总共<%=totalpage%>页共<%=total%>条。
<a href="usermanagement.jsp?list=<%=strLx%>&page=1">第一页</a>&nbsp;
<a href="usermanagement.jsp?list=<%=strLx%>&page=<%=prePage%>">上一页</a>&nbsp;
<a href="usermanagement.jsp?list=<%=strLx%>&page=<%=nextPage%>">下一页</a>&nbsp;
<a href="usermanagement.jsp?list=<%=strLx%>&page=<%=totalpage%>">最后一页</a></div>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值