UrlRewrite时需要注意的问题:action以及正则表达式

myeclipse6.5+struts2-core-2.1.8.jar+urlrewrite-3.2.0.jar如果存在开发环境的问题,那么自己先建立一个项目,把相应的文件导入即可

1.注意:为了实现action访问的伪静态在web.xml中配置struts2和urlrewrite时,加上

<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>


	<!-- url重写的过滤器 -->
	<filter>
		<filter-name>UrlRewriteFilter</filter-name>
		<filter-class>
			org.tuckey.web.filters.urlrewrite.UrlRewriteFilter
		</filter-class>
		<init-param>
			<param-name>confReloadCheckInterval</param-name>
			<param-value>20</param-value>
		</init-param>
		<init-param>
			<param-name>logLevel</param-name>
			<param-value>WARN</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>UrlRewriteFilter</filter-name>
		<url-pattern>/*</url-pattern>
		<dispatcher>REQUEST</dispatcher>
		<dispatcher>FORWARD</dispatcher>
	</filter-mapping>


	<!-- struts2过滤器 -->
	<filter>
		<filter-name>struts2-execute</filter-name>
		<filter-class>
			org.apache.struts2.dispatcher.FilterDispatcher
		</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>struts2-execute</filter-name>
		<url-pattern>*.action</url-pattern>
		<dispatcher>REQUEST</dispatcher>
		<dispatcher>FORWARD</dispatcher>
	</filter-mapping>


2.注意:匹配字符串的时候或者每一个参数的时候都需要用小括号括起来



	<!-- 点击footer链接去对应的footerPage页面 -->
	<rule>
		<from>^/footer/([\w\s*]+)$</from>
		<to>/member/pages!toFooterPage.action?name=$1</to>
	</rule>
	<outbound-rule>
		<from>member/pages!toFooterPage.action\?name=([\w\s*]+)$</from>
		<to>/footer/$1</to>
	</outbound-rule>



就上面这个两个小问题,让我在使用UrlRewrite的时候折磨惨咯!带血的经验啊!





.

你可能感兴趣的:(正则表达式,struts2,action,urlrewrite)