【问题标题】:JspException when evaluating the body评估正文时出现 JspException
【发布时间】:2014-12-14 08:27:14
【问题描述】:

目前,我遇到了一个与使用 SpringMVC 在 JSP 文件中使用标签有关的问题。 如果我手动使用复选框类型,它会正确运行

<input type="checkbox" 
                            value="${id}" name="${listCompare}" />

但是当我使用而不是上面的时,它在评估主体时通知“JspException”

td><form:checkbox path="${listCompare}" value="${id}"/></td>

以下是系统通知的问题的详细信息:

HTTP ERROR 500

Problem accessing /web/top.product. Reason:JspException when evaluating the body

Caused by:

java.io.IOException: JspException when evaluating the body
    at org.apache.tiles.request.jsp.autotag.JspModelBody.evaluate(JspModelBody.java:64)
    at org.apache.tiles.autotag.core.runtime.AbstractModelBody.evaluateWithoutWriting(AbstractModelBody.java:77)
    at org.apache.tiles.template.InsertDefinitionModel.execute(InsertDefinitionModel.java:97)
    at org.apache.tiles.jsp.taglib.InsertDefinitionTag.doTag(InsertDefinitionTag.java:254)
    at org.apache.jsp.jsp.user_page_top_rank_jsp._jspx_meth_tiles_insertDefinition_0(org.apache.jsp.jsp.user_page_top_rank_jsp:117)
    at org.apache.jsp.jsp.user_page_top_rank_jsp._jspService(org.apache.jsp.jsp.user_page_top_rank_jsp:89)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:109)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    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:820)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:401)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:450)
    at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:327)
    at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:126)
    at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:209)
    at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:267)
    at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1221)
    at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1005)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:952)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet

下面是我使用的jsp文件

<tiles:insertDefinition name="dataTemplate">
<tiles:putAttribute name="body">
    <!--End topicpath-box-->
    <div class="primary">
        <div class="menutabbar">
            <div class="title-sp">
                <p>
                    <a href="#">'${title}'.</a>
                </p>
            </div>

            <!--End tab-list-->
        </div>
        <!--End menutabbar-->
        <form:form method="GET" action="detail.compare">
            <table>
                <tr class="row-head">
                    <td class="col-head1 c1">#</td>
                    <td class="col-head1 c2">Bank</td>
                    <td class="col-head1 c6 text-center">ProductName</td>
                    <td class="col-head1 c7 text-center">ProductType</td>
                    <td class="col-head1 c4 text-center">Term</td>
                    <td class="col-head1 c5 text-center">Rate</td>
                    <td class="col-head1 c8"><a href="" type="submit"><img
                            src="resources/images/icon-so-sanh.png"
                            title="CompareDetail)"
                            alt="icon-so-sanh" /></a></td>
                </tr>
                <c:forEach items="${pageItems}" var="item" varStatus="loop">
                    <tr class="row-head2">
                        <td class="col-head2 c1">${loop.index + 1}</td>
                        <td class="col-head2 c2"><a href="${item.product.url}"><img
                                src="resources/logos/${fn:toLowerCase(item.product.bName)}.png"
                                alt="${item.product.bName}" /></a></td>
                        <td class="col-head2 c3 text-left"><c:choose>
                                <c:when test="${item.product.typeName != null}">
                                    ${item.product.typeName}
                            </c:when>
                                <c:otherwise>
                                    <c:forEach items="${item.types}" var="type" varStatus="loop">
                                        <c:if test="${type.key == item.product.productType}">
                                            ${type.value}
                                    </c:if>
                                    </c:forEach>
                                </c:otherwise>
                            </c:choose></td>
                        <td class="col-head2 c7 text-left"><a href="#"
                            ng-click="openDetailProduct('${item.product.id}','${item.term.id}')"
                            class="name-product"> ${item.product.name}</a> <span
                            class="date-product"><br />(Cập nhật: <fmt:formatDate
                                    value="${item.product.updated}" pattern="dd/MM/yyyy" />)</span></td>
                        <td class="col-head2 c4 text-center">${item.term.value}
                            ${item.term.label}</td>
                        <td class="col-head2 c5 text-center">${item.term.rate}%</td>
                        <%--<td class="col-head2 c8 checkbox"><form:checkbox
                                path="${listProductCompare}" value="${item.product.id}" /></td>--%>
                        <%-- <td class="col-head2 c8 checkbox"><input type="checkbox" 
                            value="${item.product.id}" name="${listProductCompare}" /> <label
                            for="${listProductCompare}"></label></td>   --%>
                        <td><form:checkbox path="${listProductCompare}" value="${item.product.id}"/></td>
                    </tr>
                </c:forEach>
                <tr>
                    <td colspan="3" class="ss-buttom"><input type="submit"
                        value="Submit" /></td>
                    <td colspan="7" align="right" class="ss-buttom"><a href="#"
                        CompareDetail</a></td>
                </tr>
            </table>
        </form:form>
    </div>
</tiles:putAttribute>

请告诉我造成这种情况的原因以及如何解决这种情况。 谢谢。

【问题讨论】:

  • 尝试添加一个 modelAttribute 例如

标签: java spring jsp spring-mvc web


【解决方案1】:

我假设您正在尝试将该字段绑定到支持您的表单的模型对象的名为 listProductCompare 的属性。如果是这样,那么您需要的是这个。

<form:checkbox path="listProductCompare" value="${item.product.id}"/>

而不是

<form:checkbox path="${listProductCompare}" value="${item.product.id}"/>

【讨论】:

  • 谢谢,但首先,我想在做任何事情之前先弄清楚上述问题......:(,你能告诉我上述问题的原因吗?
  • 因为 EL 表达式 ${listProductCompare} 正在寻找某个范围(页面、请求、会话等)中的 bean。
  • 如果 ${listProductCompare} 是某个范围内具有值的字符串,例如 'someProperty' 并且模型 bean 具有 get/setSomeProperty() 方法,那么这将起作用。否则你会有问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-10-28
  • 2022-01-07
  • 2020-08-11
  • 2021-05-25
  • 2022-08-13
  • 2021-06-26
  • 2020-03-24
相关资源
最近更新 更多