i've been struggling to enable multiple ulr-pattern for a web site using Spring mvc 3.0.5 sitemesh 2.4.2.my container is tomcat 6.0.26 my pom looks like this:
<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>
i'm using another view technology which is ZK for the admin site of the application.
sitemesh is supposed to take care of /site/*
and leave the /admin/*
every was fine until this week i wanted to add mobile wap view for the app.am not providing any site redirecting of the kind m.mysite.com
or mysite.mobi
, i'm just using spring mvc
request mapping to have /wap/*
which point to the same controllers and action as /site/*
. so my problem would be telling sitemesh to handle /wap/*
too.
my web.xml looks like this:
<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 -->
According to coderanch both are supposed to work though it's not about sitemesh. I think it doesn't matter since siteMeshFilter
implements javax.servlet.Filter
this is my HomeController action
@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";
}
}
Never mind, i forgot to put the pattern in the decorator.xml