Apache+tomcat迁移到apache+Weblogic整合之动静分离问题?困惑两天了~
先看看我的WEB应用是用Spring MVC 3.0.4做的,在Apache(mod_jk)+tomcat的时候完全没有问题。1. web.xml配置,注意url-pattern,是处理所有的请求,这是一个网站的根应用项目
。
<servlet-name>cts-web</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/webmvc-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>cts-web</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
2. 上面为什么spring要拦截所有请求呢,是因为在处理URL路径时更方便,URL更友好,这就是spring MVC好用的地方,不需要专门的url rewrite
//处理首页
@RequestMapping(value = "/", method = {RequestMethod.GET, RequestMethod.POST})
public ModelAndView index(HttpServletResponse resp, HttpServletRequest req) throws Exception {
// TODO: something
ModelAndView result = new ModelAndView("index");
return result;
}
//处理learn首页
@RequestMapping(value = "/learn", method = { RequestMethod.GET })
//处理一级分类
@RequestMapping(value = "/learn/{sectionName}", method = { RequestMethod.GET })
public ModelAndView sectionIndex(@PathVariable String sectionName)
//处理二级分类
@RequestMapping(value = "/learn/{sectionName}/{categoryName}/{currPage}", method = { RequestMethod.GET })
public ModelAndView categoryIndex(@PathVariable String sectionName,@PathVariable String categoryName,@PathVariable Integer currPage)
3. spring-mvc.xml配置,开发的时候静态内容不经过Spring MVC处理,直接交给容器
<!--静态内容不经过Spring MVC处理,直接交给容器 -->
<mvc:resources location="/images/" mapping="/images/**"/>
<mvc:resources location="/styles/" mapping="/styles/**"/>
<mvc:resources location="/scripts/" mapping="/scripts/**"/>
4. httpd.conf配置,在cts-web目录中放入静态内容
JkAutoAlias "D:\apache-www\cts-web"
JkMount /* cts
JkUnMount /images/* cts
JkUnMount /styles/* cts
JkUnMount /scripts/* cts
至此,apache+tomcat整合动静分离完全没有问题,run了好几个月。
-----------------------------------------------------------------------------
现在换成weblogic做应用服务器了,和apache整合就出问题了。
用的是weblogic的plug in来整合,如果不做静态文件分离,下面的配置完全能够跑起来了,没有任何问题。
LoadModule weblogic_module modules/mod_wl_22.so
<IfModule mod_weblogic.c>
WebLogicHost localhost
WebLogicPort 7001
MatchExpression *
</IfModule>
现在问题出来了,我如何才能把静态文件分离出来呢?
1. mod_weblogic只有MatchExpression,他是正向匹配的,不像JkUnMount可以反向排除?
2. 我的应用中动态处理的url有些有后缀名,有些没有(上面有详细描述),干脆直接就是个目录,比如 http://www.sample.com/jobs,导致没法用MatchExpression来匹配?
3. 在不修改我的程序的基础上有没有办法做到:apache+weblogic整合,并且做到静态文件分离由apache处理呢?
页:
[1]