论坛首页 Java版 Struts

Resin2下配置struts2

浏览 332 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
时间:2008-06-06 关键字: resin2
最近想试用一下struts2的应用,发现在resin3和tomcat服务器上面都很好配置,测试都通过了,不过公司用的都是resin2的服务器,配置好后,访问action都返回404错误,配置如下
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
  PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
  "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
	<display-name>basewww</display-name>
	
	<filter>
		<filter-name>struts2</filter-name>
		<filter-class>
			org.apache.struts2.dispatcher.FilterDispatcher
		</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>struts2</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
</web-app>


最后发现web.xml中web-app参数有问题resin2中不支持
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" 
version="2.4"> 


有那位朋友知道resin2中如何配置?
   
时间:2008-06-07
找到一个办法:
因为struts2的服务方式为filter方式,而Resin的mod_caucho插件正常情况下仅会对Servlet,Jsp服务,不会对Filter过滤的网址服务,这给struts2在Resin上使用带来一些问题。这可使用"Special servlet-mappings",详细情况可以参考http://www.caucho.com/resin-3.0/install/plugin-dispatch.xtp。
也就是说,对于一些特殊的url,可以使用plugin_match来让resin来服务,而plugin_ignore的作用正好相反。
在这里,我们需要plugin_match,为了避免打乱正常的配置,我们使用和web.xml文件相同作用的resin-web.xml来设置相应的url,这样设置仅对resin有效,不影响其他server,还是不错的。

最后的resin-web.xml是这样的:
<web-app xmlns="http://caucho.com/ns/resin">
<servlet-mapping url-pattern='/struts/*' servlet-name='plugin_match'/>
<servlet-mapping url-pattern='/other/*' servlet-name='plugin_match'/>
<servlet-mapping url-pattern='*.action' servlet-name='plugin_match'/>
<servlet-mapping url-pattern='*.html' servlet-name='plugin_match'/>
<servlet-mapping url-pattern='*.do' servlet-name='plugin_match'/>
<servlet-mapping url-pattern='/dwr/*' servlet-name='plugin_match'/>
</web-app>

这样struts2的action就可以正常工作了。
   
0 请登录后投票
时间:2008-06-07
跟据这个发现只要在apache中加入
AddHandler caucho-request action
struts2就跟resin2完美结合。
   
0 请登录后投票
论坛首页 Java版 Struts

跳转论坛:
JavaEye推荐