在处理 Spring MVC 和 Apache 磁贴时出现此错误

Getting this error while working on Spring MVC and Apache tiles

不知道哪里出错了

message

Request processing failed; nested exception is org.apache.tiles.impl.CannotRenderException:
    org.apache.tiles.util.TilesIOException: 
        JSPException including path '/WEB-INF/views/hotels/enterBookingInfo.jsp'.

说明服务器遇到内部错误,无法完成此请求。

exception

org.springframework.web.util.NestedServletException:
    Request processing failed; nested exception is org.apache.tiles.impl.CannotRenderException:
        org.apache.tiles.util.TilesIOException: JSPException including path '/WEB-INF/views/hotels/enterBookingInfo.jsp'.
        org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:656)
        org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
        org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
        org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

root cause

org.apache.tiles.impl.CannotRenderException: org.apache.tiles.util.TilesIOException:
    JSPException including path '/WEB-INF/views/hotels/enterBookingInfo.jsp'.
    org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:692)
    org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:644)
    org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:627)
    org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:321)
    org.springframework.web.servlet.view.tiles2.TilesView.renderMergedOutputModel(TilesView.java:124)
    org.springframework.js.ajax.tiles2.AjaxTilesView.renderMergedOutputModel(AjaxTilesView.java:131)
    org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1047)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

tiles.xml定义如下

<tiles-definitions>
    <definition name="enterBookingInfo" extends="standardLayout">
        <put-attribute name="body" value="/WEB-INF/views/hotels/enterBookingInfo.jsp"> </put-attribute>
    </definition>
</tiles-definitions>

Tiles 配置提取

<beans:bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
    <beans:property name="definitions">
        <beans:value>
            /WEB-INF/**/tiles.xml
        </beans:value>
    </beans:property>
</beans:bean>

我通过将表单的 commandName 属性设置为我的控制器中使用的 modelAttribute 对象的名称来解决这个问题。

我还必须修改方法语法,使 BindingResult 参数必须跟在 ModelAttribute 对象之后。

public String ultimateBooking(@RequestParam("hotelId") String hotelId,@ModelAttribute("booking") Booking bookingValidation,BindingResult result,ModelMap model)

未对 tile.xml

进行任何更改