一尘不染

从jsp el中的对象获取布尔属性

jsp

我在jsp页面上下文中有以下对象的实例:

Class User{
  private boolean isAdmin;
  public boolean isAdmin(){return isAdmin}
}

如何从EL查询isAdmin属性?这似乎不起作用:

${user.admin}

也没有:

${user.isAdmin}

谢谢!

-摩根


阅读 331

收藏
2020-06-08

共1个答案

一尘不染

好。我真笨。否决这个问题,嘲笑我,等等。问题出在isAdmin()委托给的方法中。该方法中存在一个空指针异常。但是,以我的辩护,我会说我所得到的堆栈跟踪有点不清楚,并使其看起来像是EL问题,而不是代码中的简单空指针。

醋,您可以保证即使没有属性,isAdmin()仍能正常工作,这确实帮助我解决了这一问题。感谢那。

javax.el.ELException: java.lang.NullPointerException
        at javax.el.BeanELResolver.getValue(BeanELResolver.java:298)
        at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:175)
        at com.sun.el.parser.AstValue.getValue(AstValue.java:138)
        at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:206)
        at org.apache.jasper.runtime.PageContextImpl.evaluateExpression(PageContextImpl.java:1001)
        at org.apache.jsp.WEB_002dINF.jsp.managepermissions_jsp._jspx_meth_c_forEach_1(org.apache.jsp.WEB_002dINF.jsp.managepermissions_jsp:452)
        at org.apache.jsp.WEB_002dINF.jsp.managepermissions_jsp._jspx_meth_c_forEach_0(org.apache.jsp.WEB_002dINF.jsp.managepermissions_jsp:399)
        at org.apache.jsp.WEB_002dINF.jsp.managepermissions_jsp._jspx_meth_form_form_0(org.apache.jsp.WEB_002dINF.jsp.managepermissions_jsp:348)
        at org.apache.jsp.WEB_002dINF.jsp.managepermissions_jsp._jspService(org.apache.jsp.WEB_002dINF.jsp.managepermissions_jsp:197)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:109)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:389)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:486)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:380)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:502)
        at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:363)
        at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
        at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
        at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766)
        at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:417)
        at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:334)
        at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:126)
        at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:240)
        at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:252)
        at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1173)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:901)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:523)
        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:463)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
2020-06-08