怎样用javaBean+Servlet+jsp在原有查询界面进行做分页代码如下: 20
Servletpackagecom.cn;importjava.io.IOException;importjava.util.List;importjavax.servl...
Servlet
package com.cn;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class US extends HttpServlet {
private static final long serialVersionUID = 1L;
DB sd=new DB();
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
request.setCharacterEncoding("gbk");
response.setCharacterEncoding("gbk");
String sql = "select * from userinfo order by id";
request.setAttribute("list", List);
request.getRequestDispatcher("userManager.jsp").forward(request,
response);
}
} 展开
package com.cn;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class US extends HttpServlet {
private static final long serialVersionUID = 1L;
DB sd=new DB();
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
request.setCharacterEncoding("gbk");
response.setCharacterEncoding("gbk");
String sql = "select * from userinfo order by id";
request.setAttribute("list", List);
request.getRequestDispatcher("userManager.jsp").forward(request,
response);
}
} 展开
1个回答
展开全部
package action;
import java.util.List;
import util.JsonUtil;
import bean.User;
import dao.PaginationUtil;
import com.opensymphony.xwork2.ActionSupport;
public class UserInfoList extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
int page=1;//中间变量
private int k;//储存最大页面数,用户最后一页
private int pageNo = 1;// 页码数初始为1
private int pagesize = 10;//页面行数
private int all;//总行数
private int allp;//总页数
private List<User> lstList;
private String lstList_Json; //用户信息封装成json
public String getLstList_Json() {
return lstList_Json;
}
public void setLstList_Json(String lstListJson) {
lstList_Json = lstListJson;
}
public int getPageNo() {
return pageNo;
}
public void setPageNo(int pageNo) {
this.pageNo = pageNo;
}
public int getPagesize() {
return pagesize;
}
public void setPagesize(int pagesize) {
this.pagesize = pagesize;
}
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page;
}
public List<User> getLstList() {
return lstList;
}
public void setLstList(List<User> lstList) {
this.lstList = lstList;
}
public int getAll() {
return all;
}
public void setAll(int all) {
this.all = all;
}
public int getK() {
return k;
}
public void setK(int k) {
this.k = k;
}
public int getAllp() {
return allp;
}
public void setAllp(int allp) {
this.allp = allp;
}
@Override
public String execute() throws Exception {
PaginationUtil nlist=new PaginationUtil();
all = nlist.allPage(); //总行数
allp = (all + pagesize -1)/pagesize;//算出总页数
if(pageNo<1){
pageNo=1;
}
if(pageNo > allp)pageNo=allp;
page = (pageNo -1)*pagesize;
// Pager<User> pager = new Pager<User>();
if(null!=nlist.findGrade(page, pagesize)){
lstList = nlist.findGrade(page,pagesize); //用户全部信息
lstList_Json = JsonUtil.listToJson(lstList); //封装成json
return "success";
}else{
return "fail";
}
}
}
import java.util.List;
import util.JsonUtil;
import bean.User;
import dao.PaginationUtil;
import com.opensymphony.xwork2.ActionSupport;
public class UserInfoList extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
int page=1;//中间变量
private int k;//储存最大页面数,用户最后一页
private int pageNo = 1;// 页码数初始为1
private int pagesize = 10;//页面行数
private int all;//总行数
private int allp;//总页数
private List<User> lstList;
private String lstList_Json; //用户信息封装成json
public String getLstList_Json() {
return lstList_Json;
}
public void setLstList_Json(String lstListJson) {
lstList_Json = lstListJson;
}
public int getPageNo() {
return pageNo;
}
public void setPageNo(int pageNo) {
this.pageNo = pageNo;
}
public int getPagesize() {
return pagesize;
}
public void setPagesize(int pagesize) {
this.pagesize = pagesize;
}
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page;
}
public List<User> getLstList() {
return lstList;
}
public void setLstList(List<User> lstList) {
this.lstList = lstList;
}
public int getAll() {
return all;
}
public void setAll(int all) {
this.all = all;
}
public int getK() {
return k;
}
public void setK(int k) {
this.k = k;
}
public int getAllp() {
return allp;
}
public void setAllp(int allp) {
this.allp = allp;
}
@Override
public String execute() throws Exception {
PaginationUtil nlist=new PaginationUtil();
all = nlist.allPage(); //总行数
allp = (all + pagesize -1)/pagesize;//算出总页数
if(pageNo<1){
pageNo=1;
}
if(pageNo > allp)pageNo=allp;
page = (pageNo -1)*pagesize;
// Pager<User> pager = new Pager<User>();
if(null!=nlist.findGrade(page, pagesize)){
lstList = nlist.findGrade(page,pagesize); //用户全部信息
lstList_Json = JsonUtil.listToJson(lstList); //封装成json
return "success";
}else{
return "fail";
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询