0

我的 webapp 有这些奇怪的问题。当我访问home.jspexample.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>
4

2 回答 2

1

最后,我通过在InternalResourceViewResolver中注释viewClass行来让它工作。

最终代码如下:

<!-- 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" />

于 2013-06-19T20:26:13.097 回答
0

当我访问 home.jsp 或 example.jsp,[snip] 但是当我想访问 example2.jsp [snip]

您为每个请求使用的 url 是什么?

您的 spring DispatcherServlet 针对匹配 *.html url 的请求进行配置。所有其他 url 都不会初始化图块。

于 2013-06-18T09:12:29.693 回答