我正在我的spring MVC项目中实现sitemesh3并获得404异常

时间:2012-05-05 10:11:20

标签: spring templates spring-mvc sitemesh

我正在我的spring MVC项目中实现sitemesh3并获得404异常。我正在关注本教程SiteMesh3现在的问题是我将我的jsp放在Web-Inf的视图文件夹中,所以我应该在decorator标签的sitemesh3.xml中给出什么路径。我在部署时尝试了很长时间但是获得了404 ....

2 个答案:

答案 0 :(得分:4)

我成功地使它成为sitemesh3 + spring mvc的工作。装饰器可以放在WEB-INF中而不会出现问题

我的目录结构如下

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

我的sitemesh3配置

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

和我的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>

请注意,如果您像我一样使用UrlRewriteFilter过滤器,您可能会遇到同样的问题。您必须在其他过滤器之前放置 ConfigurableSiteMeshFilter

它对我有用

答案 1 :(得分:0)

这对我有用:

decorators.xml:

<decorators defaultdir="/WEB-INF/decorators">
    <decorator name="login" page="login_master.jsp">
        <pattern>/login*</pattern>
    </decorator>
    <decorator name="none" page="none.jsp">
        <pattern>/report*</pattern>
    </decorator>
    <decorator name="master" page="master.jsp">
        <pattern>/*</pattern>
    </decorator>
</decorators>

None.jsp:

<html>
    <head>
        <title>
            <decorator:title />
        </title>
        <decorator:head />
    </head>
    <body>
        <decorator:body />
    </body>
</html>