帮忙看下我这个分页程序错在哪儿?
Util类: public static List<TeacherTb> getPage(List<TeacherTb> list,int currentPage,int num,int totalPage){List<TeacherTb> l=null;
int size=list.size();
int m=(currentPage-1)*num;
if(currentPage==totalPage){
l=list.subList(m,size);
}else{
l=list.subList(m,m+num);
}
return l;
}
JSP页面:
List<TeacherTb> list=(List<TeacherTb>)request.getSession().getAttribute("userlist");
int num=5;
int totalpage=0;
int currentPage=0;
if(list.size()%num==0){
totalpage=list.size()/num;
}else{
totalpage=list.size()/num+1;
}
String cpage=request.getParameter("cPage");
if(cpage!=null){
currentPage=Integer.parseInt(cpage);
}
if(currentPage<1){
currentPage=1;
}
if(currentPage>totalpage){
currentPage=totalpage;
}
List<TeacherTb> teacherList=Util.getPage(list,currentPage,num,totalpage);
<div align="center">
<a href="<%=basePath %>/adminmanage/teachermanage/admin_teachermanage.jsp?cPage=1" ><span>首页</span></a>
<a href="<%=basePath %>/adminmanage/teachermanage/admin_teachermanage.jsp?cPage=<%=currentPage-1 %>" ><span>上一页</span></a>
<span>第<%=currentPage%>页</span>
<a href="<%=basePath %>/adminmanage/teachermanage/admin_teachermanage.jsp?cPage=<%=currentPage+1 %>" ><span>下一页</span></a>
<a href="<%=basePath %>/adminmanage/teachermanage/admin_teachermanage.jsp?cPage=<%=totalpage %>" ><span>末页</span></a>
<span>共<%=totalpage %>页</span>
</div> --------------------编程问答-------------------- 报如下错误:
org.apache.jasper.JasperException: An exception occurred processing JSP page /adminmanage/teachermanage/admin_teachermanage.jsp at line 17
14: int totalpage=0;
15: int currentPage=0;
16:
17: if(list.size()%num==0){
18: totalpage=list.size()/num;
19: }else{
20: totalpage=list.size()/num+1;
并同时报了空指针 --------------------编程问答-------------------- org.apache.jasper.JasperException: An exception occurred processing JSP page /adminmanage/teachermanage/admin_teachermanage.jsp at line 17
14: int totalpage=0;
15: int currentPage=0;
16:
17: if(list.size()%num==0){
18: totalpage=list.size()/num;
19: }else{
20: totalpage=list.size()/num+1;
--------------------编程问答-------------------- 并同时报了空指针
--------------------编程问答-------------------- request.getSession().getAttribute("userlist"); //session里有"userlist"属性吗
--------------------编程问答-------------------- action里的写法:
public String getAllTeacher(){
System.out.println("开始了~~");
userlist=teacherInfoOper.getAllTeacher();
session.put("list", userlist);
return SUCCESS;
} --------------------编程问答-------------------- 很遗憾的告诉你! 这个空指针是因为你的list是null 的
就是说没有数据,如果你的list只是声明的! 那么当它为null时,那么这个list根本还没有创建实例,更加没有size的说话, 如果你要用size 可以先写成List list = new List();
那么这个list才有了size 为null时。size为0
补充:Java , 非技术区