Search code examples
springtemplatesspring-mvcsitemesh

I am implementing sitemesh3 in my spring MVC project and getting 404 exception


I am implementing sitemesh3 in my spring MVC project and getting 404 exception. I am following this tutorial SiteMesh3 now the problem is I am placing my jsp's inside Web-Inf in view Folder so what path i should give in sitemesh3.xml in decorator tag. I had tried a long but gettting 404 when deployed....


Solution

  • I successfully managed to make it work sitemesh3 + spring mvc. Decorators can be placed inside WEB-INF without problem

    my directory structure is as follow

    webapp/WEB-INF$ tree
    .
    ├── enable-jmx.xml
    ├── lnramirez-servlet.xml
    ├── sitemesh3.xml
    ├── urlrewrite.xml
    ├── views
    │   ├── about.jsp
    │   ├── blog
    │   │   └── list.jsp
    │   ├── defaultdecorator.jsp
    │   └── home.jsp
    └── web.xml
    

    my sitemesh3 configuration

    $ cat sitemesh3.xml 
    <?xml version="1.0" encoding="MacRoman"?>
    <sitemesh>
      <mapping path="/*" decorator="/WEB-INF/views/defaultdecorator.jsp"/>
    </sitemesh>
    

    and my web.xml

    <filter>
        <filter-name>sitemesh</filter-name>
        <filter-class>org.sitemesh.config.ConfigurableSiteMeshFilter</filter-class>
    </filter>
    
    <filter-mapping>
        <filter-name>sitemesh</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    
    <filter>
        <filter-name>HiddenMethodFilter</filter-name>
        <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
    </filter>
    
    <filter-mapping>
        <filter-name>HiddenMethodFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    
    <filter>
        <filter-name>UrlRewriteFilter</filter-name>
        <filter-class>
            org.tuckey.web.filters.urlrewrite.UrlRewriteFilter
        </filter-class>
    </filter>
    
    <filter-mapping>
        <filter-name>UrlRewriteFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    

    beware if you're using UrlRewriteFilter filter like myself you might run into the same trouble I had. You have to place ConfigurableSiteMeshFilter before other filters.

    It worked for me