0

我一直在努力为使用 Spring mvc 3.0.5 sitemesh 2.4.2.my 容器是 tomcat 6.0.26 的网站启用多个 ulr-pattern 我的 pom 看起来像这样:

 <dependency>
   <groupId>org.freemarker</groupId>
     <artifactId>freemarker</artifactId>
            <version>2.3.14</version>
 </dependency>
 <dependency>
   <groupId>opensymphony</groupId>
      <artifactId>sitemesh</artifactId>
          <version>2.4.2</version>
            <scope>compile</scope>
 </dependency>
  <dependency>
    <groupId>javax.servlet.jsp</groupId>
      <artifactId>jsp-api</artifactId>
      <version>2.1</version>
      <scope>provided</scope>
  </dependency>
  <dependency>
      <groupId>javax.servlet</groupId>
       <artifactId>servlet-api</artifactId>
          <version>2.5</version>
          <scope>provided</scope>
  </dependency>

我正在使用另一种视图技术,即 ZK 用于应用程序的管理站点。

sitemesh 应该照顾/site/*并让/admin/*一切都很好,直到本周我想为应用程序添加移动 wap 视图。我不提供任何类型的网站重定向,m.mysite.com或者mysite.mobi,我只是使用spring mvc请求映射来获得 /wap/* 指向相同的控制器和动作/site/*。所以我的问题是告诉sitemesh也要处理/wap/*

我的 web.xml 看起来像这样:

<servlet>
    <servlet-name>sitemesh-freemarker</servlet-name>
    <servlet-class>freemarker.ext.servlet.FreemarkerServlet</servlet-class>
    <init-param>
        <param-name>TemplatePath</param-name>
        <param-value>/WEB-INF/ui/views</param-value>
    </init-param>
    <init-param>
        <param-name>NoCache</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
        <param-name>ContentType</param-name>
        <param-value>text/html; charset=UTF-8</param-value>
        <!-- Forces UTF-8 output encoding! -->
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<!--  FreeMaker section   -->



<servlet-mapping>
    <servlet-name>sitemesh-freemarker</servlet-name>
    <url-pattern>*.ftd</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>sitemesh-freemarker</servlet-name>
    <url-pattern>*.ftl</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>sitemesh-freemarker</servlet-name>
    <url-pattern>*.html</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>sitemesh-freemarker</servlet-name>
    <url-pattern>*.dec</url-pattern>
</servlet-mapping>

<!--  End FreeMaker section  -->



<!-- Sitemesh -->

<filter>
    <filter-name>sitemesh</filter-name>
    <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
</filter>
<!--  Sitemesh   -->
<filter-mapping>
    <filter-name>sitemesh</filter-name>
    <url-pattern>/site/*</url-pattern> <!--this is decorated-->
    <url-pattern>/wap/*</url-pattern> <!--this is not -->
    <!--<dispatcher>FORWARD</dispatcher>-->
    <!--<dispatcher>REQUEST</dispatcher>-->
</filter-mapping>

<!--this bellow doesn't work as page not decorated-->
<!--<filter-mapping>-->
    <!--<filter-name>sitemesh</filter-name>-->
    <!--<url-pattern>/wap/*</url-pattern>-->
<!--</filter-mapping>-->
<!-- End of Sitemesh   -->

根据coderanch的说法,尽管这与站点网格无关,但两者都应该可以工作。我认为这无关紧要,因为siteMeshFilter实施javax.servlet.Filter

这是我的 HomeController 动作

@RequestMapping("/")
public String index(HttpServletRequest request) {
    final org.springframework.mobile.device.Device device = DeviceUtils.getCurrentDevice(request);

    if(device.isMobile()){
        return "redirect:/site/waphome";
    } else {
        return "redirect:/site/home";
    }

}


@RequestMapping(value = {"/site","/site/home","/site/home","/wap","/wap/","/wap/home"})
public String home(Model model, HttpServletRequest request, HttpSession session) {
    final org.springframework.mobile.device.Device device = DeviceUtils.getCurrentDevice(request);

   // ....

    if(device.isMobile()){
        return "waphome";
    } else {
        return "home";
    }

}
4

1 回答 1

0

没关系,我忘了把模式放在 decorator.xml

于 2012-05-29T19:45:34.930 回答