ge=page_listcount;
}
int pagewo=(intpage-1)*intpagecount+1;
if(pagewo>0){
rs.absolute(pagewo);
}
tmie=new listuser_bean[intpagecount];
int i=0;
do{ tmie=new listuser_bean(); tmie.setPass(rs.getString("password")); tmie.setName(rs.getString("username"));
} while(rs.next() && ++i < intpagecount);
}
}catch(Exception e){
e.printStackTrace();
}
setListCount(page_listcount);
setCount(pagecount);
return tmie;
}
public void setCount(int a){
this.pagecount=a;
}
public void setListCount(int b){
this.page_listcount=b;
}
public int getCount(){
return pagecount;
}
public int getListCount(){
return page_listcount;
}
}
MVC架构模式与利用JAVABEAN分页(2)
时间:2011-01-21
根据客户端数据来进行显示
package geezer_Model.geezer_user;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.sql.*;
import java.sql.*;
import geezer_controller.*;
import geezer_Database.getConnection;
public class listuser implements Geezer_Action{
public void execute(HttpServlet servler,HttpServletRequest request,HttpServletResponse response)
throws IOException{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
Statement simt=null;
ResultSet rs=null;
Connection conn=null;
int intpage=1;
int intpagecount=2;
try{
intpage = Integer.parseInt(request.getParameter("intpage"));
}catch(Exception e){
intpage=1;
}
if (intpage<=0){
intpage=1;
}
try{
intpagecount =Integer.parseInt(request.getParameter("intpagecount"));
}
catch(Exception e){
intpagecount=2;
}
listuser_bean[] pages=null;
listuser_page page=new listuser_page();
String sql="select * from userlist";
pages=page.getPage(intpage,intpagecount,sql);
out.println("count=" + page.getCount() + "<br>");
out.println("ListCount=" + page.getListCount() + "<br>");
if(intpage>page.getListCount()){
intpage=page.getListCount();
}
for (int i=0;i<pages.length;i++){ if(pages==null){ break;
} out.println(pages.getName()+" "+pages.getPass()+"<br><br>"); }
out.println("<script language=javascript>");
out.println("function check(theform,value){");
out.println("theform.intpage.value=value;");
out.println("theform.submit();");
out.println("}</script>");
out.println("<form action=/main?action=listuser method=post name=theform>");
out.println("<input type=hidden name=intpage>");
out.println("<a href=javascript:check(theform,"+(intpage+1)+");>next</a><br>");
out.println("<a href=javascript:check(theform,"+(intpage-1)+");>back</a>");
out.println("</form>");
}
}
|