Tiles 2, mapping of JSP

1.8k views Asked by At

I use Tiles 2 with Spring 3.05. I want to map jsp files to controller, e.g.

 <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>*.html</url-pattern>
        <url-pattern>*.jsp</url-pattern>
 </servlet-mapping>

When I do so, I get "[WARN] org.springframework.web.servlet.PageNotFound [No mapping found for HTTP request with URI [/WEB-INF/*.jsp]" for all tiles.

How can I exclude the tiles (from within WEB-INF) from servlet-mapping? or maybe I can explicitly map those files to tiles servlet?

2

There are 2 answers

0
Ralph On

May this sippet of my spring-context.xml helps you to build your configuration. It is based on the fact that there are two kind of tiles configuration files:

  • /WEB-INF/layouts/tiles-layouts.xml contains the tiles layout definitin
  • /WEB-INF/jsp/controllers/**/views.xml are several files that bind the view and jsp

    <bean id="viewResolver"
            class="org.springframework.web.servlet.view.UrlBasedViewResolver">
            <property name="requestContextAttribute" value="requestContext" />
            <property name="viewClass"
                    value="org.springframework.web.servlet.view.tiles2.TilesView" />
    </bean>
    
    <!-- Configure Apache Tiles for the view -->
    <bean id="tilesConfigurer"
            class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
            <property name="definitions">
                    <list>
                            <value>/WEB-INF/layouts/tiles-layouts.xml</value>
                            <value>/WEB-INF/jsp/controllers/**/views.xml</value>                           
                    </list>
            </property>
    </bean>
    

One of the /WEB-INF/jsp/controllers/**/views.xml files:

 <tiles-definitions>

    <!-- Pages -->
    <definition name="site/list" extends="standard-layout">
            <put-attribute name="title" value="List Sites" />
            <put-attribute name="body" value="/WEB-INF/jsp/controllers/site/list.jsp" />
    </definition>
    <definition name="site/show" extends="standard-breadcrumb-layout">
            <put-attribute name="title" value="Show Site" />
            <put-attribute name="breadcrumbNavigation" value="/WEB-INF/layouts/siteBreadcrumbNavigation.jsp" />
            <put-attribute name="body" value="/WEB-INF/jsp/controllers/site/show.jsp" />
    </definition>
    <definition name="site/create" extends="standard-layout">
            <put-attribute name="title" value="Create Site" />
            <put-attribute name="body" value="/WEB-INF/jsp/controllers/site/create.jsp" />
    </definition>
    <definition name="site/update" extends="standard-layout">
            <put-attribute name="title" value="Update Site" />
            <put-attribute name="body" value="/WEB-INF/jsp/controllers/site/update.jsp" />
    </definition>

 </tiles-definitions> 
0
Raghuram On

Instead of doing this in web.xml, you should probably configure it in your context file. The instructions are available in the spring docs.