我的 webapp 有这些奇怪的问题。当我访问home.jsp或example.jsp时,Tiles 正常加载,但是当我想访问example2.jsp时,作为子文件夹,布局根本不被调用。
我的目录结构如下:
webapp
|___ pages
|___ subfolder
|___ example2.jsp
|___ tiles
|___ layouts
|___ base-layout.jsp
|___ header.jsp
|___ footer.jsp
|___ example.jsp
|___ home.jsp
|___ resources
|___ WEB-INF
|___ servlet.xml
|___ tiles-defs.xml
|___ web.xml
|___ index.jsp
我的servlet.xml
<!-- JSP View Resolver -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/pages/" />
<property name="suffix" value=".jsp" />
<property name="order" value="1" />
</bean>
<!-- Default Tiles View Resolver -->
<bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver" >
<property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/>
<property name="order" value="0" />
</bean>
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer" >
<property name="definitions">
<list>
<value>/WEB-INF/tiles-defs.xml</value>
</list>
</property>
</bean>
我的tiles-defs.xml
<tiles-definitions>
<definition name="base-layout" template="/pages/tiles/layouts/base-layout.jsp">
<put-attribute name="header" value="/pages/tiles/header.jsp" />
<put-attribute name="body" value="" />
<put-attribute name="footer" value="/pages/tiles/footer.jsp" />
</definition>
<definition name="home" extends="base-layout">
<put-attribute name="title" value="Title" />
<put-attribute name="body" value="/pages/home.jsp" />
</definition>
<definition name="example1" extends="base-layout">
<put-attribute name="title" value="Title" />
<put-attribute name="body" value="/pages/example.jsp" />
</definition>
<definition name="example2" extends="base-layout">
<put-attribute name="title" value="Title" />
<put-attribute name="body" value="/pages/subfolder/example2.jsp" />
</definition>
</tiles-definitions>
我的web.xml
<servlet>
<servlet-name>myServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>myServlet</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>