我是Tiles和Spring MVC的新手。我有一个显示问题(我查看了几个类似的问题,但找不到'我的问题'的解决方案)。
这是我的'tiles-servlet.xml'配置(尝试使用UrlBasedViewResolver
和TilesViewResolver
)。
....
<bean id="viewResolver" class="org.springframework.web.servlet.view.tiles3.TilesViewResolver">
<property name="viewClass">
<value>org.springframework.web.servlet.view.tiles3.TilesView</value>
</property>
</bean>
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
<value>/WEB-INF/tiles-booking.xml</value>
</list>
</property>
</bean>
....
我的'tiles.xml'包含Tiles定义
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN" "http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
<tiles-definitions>
<definition name="base.definition" template="/WEB-INF/tiles/template/defaultLayout.jsp">
<put-attribute name="title" value="" />
<put-attribute name="header" value="/WEB-INF/tiles/template/defaultHeader.jsp" />
<put-attribute name="search" value="/WEB-INF/search/searchCriteria.jsp" />
<put-attribute name="searchResults" value="/WEB-INF/search/searchResults.jsp" />
<put-attribute name="unitDetails" value="/WEB-INF/search/unitDetails.jsp" />
<put-attribute name="footer" value="/WEB-INF/tiles/template/defaultFooter.jsp" />
<put-attribute name="body" value="/WEB-INF/tiles/template/defaultContent.jsp" />
</definition>
<definition name="indexPage" template="/WEB-INF/tiles/template/simpleLayout.jsp">
<put-attribute name="header" value="/WEB-INF/tiles/template/defaultHeader.jsp" />
<put-attribute name="title" value="Welcome to Venue Bookings" />
<put-attribute name="indexPage" value="/WEB-INF/jsp/indexPage.jsp" />
<put-attribute name="footer" value="/WEB-INF/tiles/template/defaultFooter.jsp" />
</definition>
<definition name="searchForm" extends="base.definition">
<put-attribute name="title" value="Search form" />
<put-attribute name="search" value="/WEB-INF/search/searchCriteria.jsp" />
<put-attribute name="searchResults" value="/WEB-INF/search/searchResults.jsp" />
<put-attribute name="unitDetails" value="/WEB-INF/search/unitDetails.jsp" />
</definition>
<definition name="bookConfirmationForm" extends="/WEB-INF/tiles/template/bookingLayout.jsp">
<put-attribute name="title" value="Booking Confirmation" />
<put-attribute name="booking" value="/WEB-INF/search/configmBooking.jsp" />
</definition>
</tiles-definitions>
我已经所有指定的JSP文件定义,工作且可用。所有这些人一直在安静地工作,没有问题。但是,昨天我定义了显示预订的新页面。我面临错误:
以下是例外:
org.apache.jasper.JasperException: javax.servlet.ServletException: Could not resolve view with name 'indexPage' in servlet with name 'tiles'
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:585)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
root cause: javax.servlet.ServletException: Could not resolve view with name 'indexPage' in servlet with name 'tiles'
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1190)
最后,我的控制器方法:
@RequestMapping(value = "/index")
public ModelAndView indexPage() {
Map<String, Object> model = new HashMap<String, Object>();
....
model.put("command", new SearchCriteriaBean());
return new ModelAndView("indexPage", model);
}
@RequestMapping(value = "/checkAvailability", method = RequestMethod.GET)
public ModelAndView checkAvailability(@ModelAttribute("agreedBookingRequest")
UnitBookingAgreementBean agreedBookingRequest, HttpSession session) {
.....
return new ModelAndView("bookConfirmationForm", model);
}
我认为这个错误必定是一个愚蠢的错误,但我无法弄明白。我也尝试过使用tiles2,但这没有用。
答案 0 :(得分:1)
“bookConfirmationForm”定义的extends="/WEB-INF/tiles/template/bookingLayout.jsp"
对我来说很奇怪(<definition name="bookConfirmationForm" extends="/WEB-INF/tiles/template/bookingLayout.jsp">
)。我只知道可以使用extends
参数的逻辑名称,但不能使用文件名。
我想您想要编写extends="base.definition"
,或者想要使用template
参数:
<definition name="bookConfirmationForm" extends="base.definition">
<put-attribute name="title" value="Booking Confirmation" />
<put-attribute name="booking" value="/WEB-INF/search/configmBooking.jsp" />
</definition>
<!-- or -->
<definition name="bookConfirmationForm" template="/WEB-INF/tiles/template/bookingLayout.jsp">
<put-attribute name="title" value="Booking Confirmation" />
<put-attribute name="booking" value="/WEB-INF/search/configmBooking.jsp" />
</definition>