日期:2014-05-19  浏览次数:21015 次

java.lang.NumberFormatException: For input string: ""
org.apache.jasper.JasperException: An exception occurred processing JSP page /test.jsp at line 48

45: if (currentpage == null) {
46: currentpage = "1";
47: }
48: int pageindex = Integer.parseInt(currentpage);
49: if (pageindex < 1) {
50: pageindex = 1;
51: } else if (pageindex > totalpage) {




Java code

request.setCharacterEncoding("GBK");
            page p = new page();
            int count = p.getCount();
            int pagesize = 2;
            int totalpage = p.getTotalpage(count, pagesize);
            String currentpage = request.getParameter("pageindex");
            //System.out.println(currentpage);
            if (currentpage == null) {
                currentpage = "1";
            }
            int pageindex = Integer.parseInt(currentpage);
            if (pageindex < 1) {
                pageindex = 1;
            } else if (pageindex > totalpage) {
                pageindex = totalpage;
            }
            List<News> list = p.getnewslist(pageindex, pagesize);
            //request.setAttribute("newslist", list);
            for (News news : list) {
        %>
        <%=news.getTitle()%><br />
        <%
            }
        %>
        当前页数[<%=pageindex%>/<%=totalpage%>]
        <%
            if (pageindex > 1) {
        %>
        <a href="test.jsp?pageindex=1">首页</a>&nbsp;
        <a href="test.jsp?pageindex=" <%=pageindex - 1%>>上一页</a>&nbsp;
        <%
            }
            if (pageindex < totalpage) {
        %>
        <a href="test.jsp?pageindex=" <%=pageindex + 1%>>下一页</a>&nbsp;
        <a href="test.jsp?pageindex=" <%=totalpage%>>尾页</a>&nbsp;
        <%
            }
        %>





------解决方案--------------------
if (currentpage == null || currentpage.isEmpty()) {
currentpage = "1";
}
------解决方案--------------------

探讨
if (currentpage == null || currentpage.isEmpty()) {
currentpage = "1";
}

------解决方案--------------------
jsp页面报错真麻烦,不能定位到报错的地方。不过可以确认的是,肯定是Integer.parseInt(xxxxx)报错的,xxxxx的值为“”。。。
我的异常网推荐解决方案:An exception occurred processing JSP page,http://www.aiyiweb.com/j2se/33144.html