我是 Tiles 和 Spring MVC 的新手。我的显示有问题(我查看了几个类似的问题,但没有找到“我的问题”的解决方案)。这是我的“tiles-servlet.xml”配置(用UrlBasedViewResolver
and试过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 文件,这些文件正在工作并且可用。所有这些都已经安静地工作了一段时间,没有问题。但是,昨天我定义显示一个新的预订页面。我面临错误:
- 当我评论定义“bookConfirmationForm”(如上)时,一切正常。奇怪的是,如果我启用此定义,我将面临主页本身的问题('indexPage' 视图是我的起始页面)。
- 当我评论上述定义时,一切正常,直到我达到上述观点,显然,它在那里失败了。
这是一个例外:
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);
}
我认为这个错误一定是一个愚蠢的错误,但我无法弄清楚。我也尝试过使用tile2,但这没有帮助。