想做一個歌曲的分頁顯示 出現java.lang.NumberFormatException: For input string: "null"
java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
//按songname查找歌曲
public String getSbn(){
songlist=service.getSongByName(this.songname);
currentpage=1;
//總結果數
totalresults=songlist.size();
if(totalresults%pagesize!=0){
pagenumber=(totalresults/pagesize)+1;
}
else{pagenumber=totalresults/pagesize;
}
start=(currentpage-1)*pagesize;
end=(currentpage)*pagesize-1;
request.getSession().setAttribute("songlist",songlist);
request.getSession().setAttribute("currentpage",currentpage);
request.getSession().setAttribute("pagenumber",pagenumber);
return "searchresult";
}
//下一頁
public String nextPage(){
songlist=(List<Song>) session.getAttribute("songlist");
totalresults=songlist.size();
//將object轉化成int
//此處"currentpage"為空
currentpage= Integer.parseInt(String.valueOf(request.getSession().getAttribute("currentpage")));
currentpage++;
request.getSession().setAttribute("currentpage",currentpage);
if(totalresults%pagesize!=0){
pagenumber=(totalresults/pagesize)+1;
}
else{pagenumber=totalresults/pagesize;
}
start=(currentpage-1)*pagesize;
end=(currentpage)*pagesize-1;
return"addsongok";
}
jsp上調用nextpage()的部分
<% if((session.getAttribute("currentpage")!=null)&&(session.getAttribute("pagenumber")!=null)){
if(Integer.parseInt(String.valueOf(request.getSession().getAttribute("currentpage")))==Integer.parseInt(String.valueOf(request.getSession().getAttribute("pagenumber"))))
{ %><% } else { %>
<a href="SongManage_nextPage?">下一頁</a>
<% }} %>
currentpage= Integer.parseInt(String.valueOf(request.getSession().getAttribute("currentpage")));這裡取回的currentpage為空。請問是為什麼?
既用 session.getAttribute("songlist");
又用 request.getSession().getAttribute("currentpage")
控制台輸出一下session的id吧 可能不是同一個session了 自然就取不到值了