在Controller中使用Model自带的put方法携带非Model属性的值。 userInfo.put("score", totalScore); userInfo.put("studyScore", studySocre); setAttr("user", userInfo);
在JSP中使用JSTL获取user 中的score和studyScore值,出现下面异常,在网页上无法获取以上设置的属性:
javax.el.PropertyNotFoundException: Property 'score' not found on type com.yqdz.biz.model.User at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:193) at javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:170) at javax.el.BeanELResolver.property(BeanELResolver.java:279) at javax.el.BeanELResolver.getValue(BeanELResolver.java:60) at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54) at org.apache.el.parser.AstValue.getValue(AstValue.java:123) at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186) at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:935) at org.apache.jsp.user.userProfile_jsp._jspService(userProfile_jsp.java:233) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646) at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436) at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374) at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302) at com.jfinal.render.JspRender.render(JspRender.java:67) at com.jfinal.core.ActionHandler.handle(ActionHandler.java:97) at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:72) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Thread.java:745)
但是在Java代码Debug和JSP debug响应数据中又包含有score和studyScore的值。无解了.....
如下截图:
Java 代码Debug信息:
JSP 代码Debug信息:
JFinal其他版本的我以前也遇到这个问题,都是通过手动在BaseModel中手动添加属性解决。
不知道其他小伙伴有遇到这个问题没?
项目:JFinal
解决的办法是配置一下:
ModelRecordElResolver.setResolveBeanAsModel(true)
这样 jstl 处理 model 时会调用其 get(String attrName) 方法,而不会理会 getter 方法
如果希望这个处理更加智能,建议使用 jfinal template engine