/**
* @(#)Welcome.java * *
* @author
* @version 1.00 2017/2/10 */
//»¶Ó½çÃæ
package com.tsinghua; import javax.servlet.http.*; import java.io.*; import java.sql.*; import java.util.*;
public class Welcome extends HttpServlet{
//´¦ÀígetÇëÇó
public void doGet(HttpServletRequest req,HttpServletResponse res){
//ÒµÎñÂß¼
Connection ct=null;
PreparedStatement ps=null; ResultSet rs=null;
//ÒµÎñÂß¼ try { //µÃµ½session
HttpSession hs=req.getSession(true); String val=(String)hs.getAttribute(\ String name=\
String passwd=\ÀïÃæ²»ÓÃд¿Õ¸ñ
//ÅжÏÊÇ·ñ·Ç·¨µÇ½ if(val==null){ try{ //Èç¹ûsessionÖÐûÓÐÓû§ÐÅÏ¢£¬ÔÙ¿´¿´cookieÖÐÓÐûÓÐÓû§ÐÅÏ¢ //´Ó¿Í»§¶ËµÃµ½ËùÓÐcookieÐÅÏ¢ Cookie[] allCookies=req.getCookies(); int i=0; //Èç¹ûallCookie²»Îª¿Õ if(allCookies!=null){ //´ÓÖÐÈ¡³öcookie for(i=0;i ex.printStackTrace(); } } else{ //µÃµ½´ÓLogincl´«µÝµÄÓû§Ãû String un=req.getParameter(\ //µÃµ½´ÓLoginClÖд«µÝµÄÃÜÂë String up=req.getParameter(\ //Êä³öweclcome //ÖÐÎÄÂÒÂë½â¾ö·½·¨ res.setContentType(\ PrintWriter pw=res.getWriter(); pw.println(\ pw.println(\ //===========·ÖÒ³============= int pageSize=3;//Ò»Ò³ÏÔʾ¶àÉټǼ int pageNow=1;//Ï£ÍûÏÔʾµÚ¼¸Ò³£¬¼´Ò³Âë //¶¯Ì¬½ÓÊÜpageNow String sPageNow=req.getParameter(\ if (sPageNow==null){ //Óû§µÚÒ»´Î½øÈëwel }else{ pageNow=Integer.parseInt(sPageNow); } //µ÷ÓÃUserBeanCl UserBeanCl ubc=new UserBeanCl(); ArrayList al=ubc.getResultByPage(pageNow,pageSize); //±íÍ· pw.println(\ pw.println(\ for(int i=0;i pw.println(\ÉÏÒ»Ò³\ //ÏÔʾ³¬Á´½Ó£¨£© for(int i=1;i<=pageCount;i++){ pw.println(\ } //ÏÔʾÏÂÒ»Ò³ if(pageNow!=pageCount) pw.println(\ÏÂÒ»Ò³\ //ÔÚservletÖÐÏÔʾͼƬ pw.println(\ pw.println(\ } catch (Exception ex){ ex.printStackTrace(); } } public void doPost(HttpServletRequest req,HttpServletResponse res){ this.doGet(req,res); } } ConnDB /** * @(#)ConnDB.java * Á´½ÓÊý¾Ý¿â * * @author * @version 1.00 2017/2/18 */ package com.tsinghua; import java.sql.*; public class ConnDB { private Connection ct=null; public Connection getConn(){ try{ //Á´½ÓÊý¾Ý¿â,¼ÓÔØÇý¶¯ Class.forName(\ //µÃµ½Á´½Ó ct=DriverManager.getConnection(\/xcdb?useUnicode=true&characterEncoding=gbk\ }catch (Exception ex){ ex.printStackTrace(); } return ct; } } UserBean /** * @(#)UserBean.java * ÕâÊÇÒ»¸öuserBean ËûºÍuer±íÓ³Éä * ËûµÄÒ»¸ö¶ÔÏóºÍuser±íµÄÒ»Ìõ¼Ç¼¶ÔÓ¦ * @author * @version 1.00 2017/2/18 */ package com.tsinghua; public class UserBean { private int userId; private String username; private String password; private String email; private int grade; public void setUserId(int userId){ this.userId=userId; } public int getUserId(){ return this.userId; } public void setUserName(String username){ this.username=username; } public String getUserName(){ return this.username; } public void setPassword(String password){ this.password=password; } public String getPassword(){ return this.password; } public void setEmail(String email){ this.email=email; } public String getEmail(){ return this.email; } public void setGrade(int grade){ this.grade=grade; } public int getGrade(){ return this.grade; } } UserBeanCl /** * @(#)UserBeanCl.java * ÕâÊÇÒ»¸ö´¦ÀíÀ࣬Ö÷Òª´¦Àíuser±í£¬userBean * Ö÷ÒªÊÇÒµÎñÂß¼ * @author * @version 1.00 2017/2/18 */ package com.tsinghua; import java.sql.*; import java.util.*; public class UserBeanCl { //ÒµÎñÂß¼ private Connection ct=null; private PreparedStatement ps=null; private ResultSet rs=null; private int pageCount=0;//¹²Óм¸Ò³£¨¼ÆËã³öÀ´µÄ£© public int getPageCount(){ return this.pageCount; } //·ÖÒ³ÏÔʾ public ArrayList getResultByPage(int pageNow,int pageSize){ ArrayList al=new ArrayList(); try{ int rowCount=0;//¹²Óм¸Ìõ¼Ç¼£¨²é±í£© int start=0;//¿ªÊ¼µÚ¼¸Ìõ //Ê×Ïȵõ½rowCount ConnDB cd=new ConnDB(); ct=cd.getConn(); ps=ct.prepareStatement(\ rs=ps.executeQuery(); if(rs.next()){ rowCount=rs.getInt(1); } //¼ÆËãpageCount if(rowCount%pageSize==0){ pageCount=rowCount/pageSize; }else{ pageCount=rowCount/pageSize+1;