jsp前台 all=0没有数据啊
<form action="AdminServlet?flag=List" method="post" name="name">
<%
PageHelp ph = (PageHelp)request.getAttribute("all");
List all = ph.getPageList();
%>
Servlet接收
if ("List".equals(flag)) {
String ID = request.getParameter("ID");
int id = 0;
if (ID != null && !"".equals(ID)) {
id = Integer.parseInt(ID);
}
String userName = request.getParameter("username");
String role = request.getParameter("role");
String quanxian = request.getParameter("quanxian");
List all = new ArrayList();
PageHelp ph = new PageHelp();
ph.setPageSize(10);
int page = 1;
int startRow = 0;
String pageNo = request.getParameter("page");
if (pageNo != null) {
page = Integer.parseInt(pageNo);
}
ph.setCurPage(page);
startRow = (page - 1) * (ph.getPageSize());
ph.setTotulRows(DaoFactory.getAdminDaoInstance().getTotulRows(
userName, role, quanxian));
ph.init(ph.getTotulRows());
all = DaoFactory.getAdminDaoInstance().getAll(startRow,
ph.getPageSize(), id, userName, role, quanxian);
ph.setPageList(all);
request.setAttribute("all", ph);
path = "./admin/adminList.jsp";
} } request.getRequestDispatcher(path).forward(request, response);
<form action="AdminServlet?flag=List" method="post" name="name">
<%
PageHelp ph = (PageHelp)request.getAttribute("all");
List all = ph.getPageList();
%>
Servlet接收
if ("List".equals(flag)) {
String ID = request.getParameter("ID");
int id = 0;
if (ID != null && !"".equals(ID)) {
id = Integer.parseInt(ID);
}
String userName = request.getParameter("username");
String role = request.getParameter("role");
String quanxian = request.getParameter("quanxian");
List all = new ArrayList();
PageHelp ph = new PageHelp();
ph.setPageSize(10);
int page = 1;
int startRow = 0;
String pageNo = request.getParameter("page");
if (pageNo != null) {
page = Integer.parseInt(pageNo);
}
ph.setCurPage(page);
startRow = (page - 1) * (ph.getPageSize());
ph.setTotulRows(DaoFactory.getAdminDaoInstance().getTotulRows(
userName, role, quanxian));
ph.init(ph.getTotulRows());
all = DaoFactory.getAdminDaoInstance().getAll(startRow,
ph.getPageSize(), id, userName, role, quanxian);
ph.setPageList(all);
request.setAttribute("all", ph);
path = "./admin/adminList.jsp";
} } request.getRequestDispatcher(path).forward(request, response);
PreparedStatement prem = null;
Connection conn = null;
ResultSet rs = null;public List<Admin> findgetAll() throws Exception {
String sql="select id,username,userpass,role,quanxian from admin";
prem=conn.prepareStatement(sql);//这里报错
rs=prem.executeQuery();
List<Admin> all=new ArrayList();
Admin admin=null;
while(rs.next()){
admin=new Admin();
admin.setId(rs.getInt(1));
admin.setUserName(rs.getString(2));
admin.setUserPass(rs.getString(3));
admin.setRole(rs.getString(4));
admin.setQuanxian(rs.getString(5));
all.add(admin);
}
public static void main(String[] args) {
AdminDao a=new AdminDaoImpl();
try {
List<Admin> l=a.findgetAll();
for(Iterator<Admin> it=l.iterator();it.hasNext();){
Admin ad=(Admin) it.next();
System.out.println(ad.getId(),ad.getRole(),ad.getQuanxian(),ad.getUserName(),ad.getUserPass());
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
连接对象位null
本应该是 conn=db.getConn();吗
空指针