JFinal在Controller中setAttr()数据之后,在前台获取不到传递的值

我在controller中获取到的分页数据后通过setAttr()传递给前台页面

System.out.println("pageNumber:" + pageNumber);

Page<User> userpage = User.dao.paginate(pageNumber, 5, "select *","from user where id>?",0);

setAttr("userPage",userpage);

render("list.jsp");

在前台获取不到值

    <c:forEach items="${userPage.list}" var="user">

        <tr>

            <td>${user.name}</td>

            <td>${user.gender}</td>

            <td>${user.phone}</td>

            <td>${user.email}</td>

            <td>${user.description}</td>

            <td>

                <a href="../user/edit/${user.id }">修改</a>

                <a href="../user/del/${user.id }">删除</a>

            </td>

        </tr>

    </c:forEach>

// 分也部分

<div>

        <nav>

            <ul>

                <%--判断userPage.pageNumber是否大于1,如果是则上一页为userPage.pageNumber-1,否则为1--%>

                <%--也就是说在当前页userPage.pageNumber为1时,也有上一页的超链接,只不过跳转到第1页,即当前页--%>

                <%--下一页同理--%>

                <li><a href="user/list?pageNumber=${userPage.pageNumber>1?userPage.pageNumber-1:1 }">上一页</a></li>


                <c:forEach begin="1" end="${userPage.totalPage}" varStatus="page">

                    <a href="user/list?pageNumber=${page.index }">${page.index }</a>

                </c:forEach>


                <li><a href="user/list?pageNumber=${userPage.pageNumber<userPage.totalPage?userPage.pageNumber+1:userPage.totalPage }">下一页</a></li>

            </ul>

        </nav>

    </div>



运行后控制台报错:

017-10-18 17:06:20

[ERROR]-[Thread: http-bio-8080-exec-2]-[com.jfinal.core.ActionHandler.handle()]: /user/list

com.jfinal.render.RenderException: org.apache.jasper.JasperException: Unable to compile class for JSP

at com.jfinal.render.JspRender.render(JspRender.java:69)

at com.jfinal.core.ActionHandler.handle(ActionHandler.java:99)

at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:74)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)

at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)

at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)

at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115)

at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)

at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)

at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

at java.lang.Thread.run(Unknown Source)

Caused by: org.apache.jasper.JasperException: Unable to compile class for JSP

at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:675)

at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:364)

at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)

at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:743)

at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:485)

at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:410)

at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:337)

at com.jfinal.render.JspRender.render(JspRender.java:67)

... 19 more

Caused by: java.lang.NumberFormatException: For input string: "${userPage.totalPage}"

at java.lang.NumberFormatException.forInputString(Unknown Source)

at java.lang.Integer.parseInt(Unknown Source)

at java.lang.Integer.valueOf(Unknown Source)

at org.apache.jasper.compiler.JspUtil.coerceToInt(JspUtil.java:605)

at org.apache.jasper.compiler.Generator$GenerateVisitor.convertString(Generator.java:3246)

at org.apache.jasper.compiler.Generator$GenerateVisitor.evaluateAttribute(Generator.java:3055)

at org.apache.jasper.compiler.Generator$GenerateVisitor.generateSetters(Generator.java:3160)

at org.apache.jasper.compiler.Generator$GenerateVisitor.generateCustomStart(Generator.java:2346)

at org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1831)

at org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1553)

at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2392)

at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2444)

at org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2450)

at org.apache.jasper.compiler.Node$Root.accept(Node.java:474)

at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2392)

at org.apache.jasper.compiler.Generator.generate(Generator.java:3591)

at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:251)

at org.apache.jasper.compiler.Compiler.compile(Compiler.java:374)

at org.apache.jasper.compiler.Compiler.compile(Compiler.java:354)

at org.apache.jasper.compiler.Compiler.compile(Compiler.java:341)

at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:660)

... 33 more

十月 18, 2017 5:06:20 下午 org.apache.catalina.core.ApplicationDispatcher invoke

严重: Servlet.service() for servlet jsp threw exception

java.lang.NumberFormatException: For input string: "${userPage.totalPage}"

at java.lang.NumberFormatException.forInputString(Unknown Source)

at java.lang.Integer.parseInt(Unknown Source)

at java.lang.Integer.valueOf(Unknown Source)

at org.apache.jasper.compiler.JspUtil.coerceToInt(JspUtil.java:605)

at org.apache.jasper.compiler.Generator$GenerateVisitor.convertString(Generator.java:3246)

at org.apache.jasper.compiler.Generator$GenerateVisitor.evaluateAttribute(Generator.java:3055)

at org.apache.jasper.compiler.Generator$GenerateVisitor.generateSetters(Generator.java:3160)

at org.apache.jasper.compiler.Generator$GenerateVisitor.generateCustomStart(Generator.java:2346)

at org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1831)

at org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1553)

at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2392)

at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2444)

at org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2450)

at org.apache.jasper.compiler.Node$Root.accept(Node.java:474)

at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2392)

at org.apache.jasper.compiler.Generator.generate(Generator.java:3591)

at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:251)

at org.apache.jasper.compiler.Compiler.compile(Compiler.java:374)

at org.apache.jasper.compiler.Compiler.compile(Compiler.java:354)

at org.apache.jasper.compiler.Compiler.compile(Compiler.java:341)

at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:660)

at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:364)

at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)

at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:743)

at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:485)

at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:410)

at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:337)

at com.jfinal.render.JspRender.render(JspRender.java:67)

at com.jfinal.core.ActionHandler.handle(ActionHandler.java:99)

at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:74)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)

at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)

at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)

at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115)

at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)

at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)

at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

at java.lang.Thread.run(Unknown Source)

请教各位大神给看看这是怎么回事儿。。谢谢了

评论区

JFinal

2017-10-18 17:32

打 war 包的时候,注意 jetty 相关的 jar 包不要打进去,jetty 的 jar 仅用于开发阶段。

如果你在使用 jetty 时,用的是 maven 项目,并且 dependency 是中的 scope 是 provoided 的,那么不会打进去

此外,看看是不是这些个问题:
http://blog.csdn.net/baimin7657/article/details/8650434
http://blog.csdn.net/u011781521/article/details/53713162
http://blog.csdn.net/bestcxx/article/details/51740652

大帅先森ES

2017-10-18 17:56

@JFinal 应该不是这些问题,那个错误里边说"${userPage.totalPage}"这个值是控值,然后引起的jsp页面语法错误,然后我在前台页面把他换成固定数字之后,页面可以正常加载,也不会再报这个错误“Unable to compile class for JSP”,不知道是什么原因在前台拿到的数据是空的

热门反馈

扫码入社