mysql 分页


<%@ page language="java" import="java.util.*,java.sql.*,com.abin.db.connection.*,java.text.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>DIV+CSS</title>
  </head>
  <body>
<%
	Connection conn=null;
	Statement stmt=null;
	ResultSet rs=null;
	String sql=null;
	int pagesize=3;
	int pagenum=1;
	if(request.getParameter("pageno")!=null||!"".equals(request.getParameter("pageno"))){
		pagenum=Integer.parseInt(request.getParameter("pageno"));
	}
	if(request.getParameter("pageno")==null||"".equals(request.getParameter("pageno"))){
		pagenum=1;
	}
	int pp=(pagenum-1)*pagesize;
	try{
		conn=DBClassMysql.getMysql();
		sql="select * from test order by createtime desc limit "+pp+","+pagesize;
		stmt=conn.createStatement();
		rs=stmt.executeQuery(sql);
		out.println("<table border=2>");
		out.println("<tr>");
		out.println("<th width=200>"+"company"+"</th>");
		out.println("<th width=200>"+"content"+"</th>");
		out.println("<th width=200>"+"comployee"+"</th>");
		out.println("</tr>");
		while(rs.next()){
			out.println("<tr>");
			out.println("<td>"+rs.getString("company")+"</td>");
			out.println("<td>"+rs.getString("content")+"</td>");
			out.println("<td>"+rs.getString("comployee")+"</td>");
			out.println("</tr>");
		}
		out.println("</table>");
		
		
	}catch(Exception e){
		e.printStackTrace();
	}finally{
		if(null!=conn){
			conn.close();
		}
		if(null!=stmt){
			stmt.close();
		}
		if(null!=rs){
			rs.close();
		}
	}
	int pagecurrent=pagenum-1;
	int pagenext=pagenum+1;
	out.println("<a href='index.jsp?pageno="+pagecurrent+"'>"+"上一页"+"</a>");
	out.println("<a href='index.jsp?pageno="+pagenext+"'>"+"下一页"+"</a>");
	out.println("<br/>");
	%>
		<form id="pid" name="pname" method="get" action="index.jsp">
			<input id="pageid" type="text" name="pageno" />
			<input type="submit" value="跳转" />
		</form>
	
	<%
	Calendar cal=Calendar.getInstance();
	SimpleDateFormat sdf=new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
	String show=sdf.format(cal.getTime());
	out.println(show);
	
	
%>	
<br/>
<a href="add.jsp">新增</a>
  </body>
</html>


你可能感兴趣的:(jsp)