当前位置: 代码迷 >> Web前端 >> Java URLRewriter应用小节
  详细解决方案

Java URLRewriter应用小节

热度:127   发布时间:2012-10-06 17:34:01.0
Java URLRewriter使用小节

最近总结了下URLRewriter.

http://fykyx521.iteye.com/blog/494263 很好地总结了页面URL重写的问题.

http://zhxing.iteye.com/blog/456713? 有较详细的翻译

1首先web.xml中要注意

<!-- URLRewriter -->
	<filter>
		<filter-name>UrlRewriteFilter</filter-name>
		<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>UrlRewriteFilter</filter-name>
		<url-pattern>/*</url-pattern>
		<dispatcher>REQUEST</dispatcher>
		<dispatcher>FORWARD</dispatcher>
	</filter-mapping>

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

http://hintcnuie.iteye.com/blog/226251 给出了关于它的详细说明

2再有页面ULR重写要注意:

<!-- rule用于页面重定向 -->
	<rule>
		<from>^/([\w\W]+).htm$</from>
		<to type="redirect">$1.action</to>
	</rule>
	<rule>
		<from>^/(\w+)/(\w+)/(\w+).html$</from>
		<to type="forward">%{context-path}/$1.action?valueInt=$2&amp;valueString=$3</to>
		<!-- %{context-path}指当前项目路径(多层次下使用).-->
		<!-- type="redirect",type="forward"(默认方式) 是另一种页面重定向方式 -->
	</rule>
	<!-- outbound-rule用于页面链接显示重定向 -->
	<outbound-rule>
		<from>^([\w\W]+).action$</from>
		<to>$1.htm</to>
	</outbound-rule>

?这里type="redirect",type="forward"(默认方式) ,如使用redirect 是页面跳转,即浏览器地址栏会显示.forward则是重定向. %{context-path}指当前项目路径.

3页面URL 若不重写意义也不大,重写方式通过outbound-rule定制,它会重写 response.encodeURL(result)然手达到重写页面URL的目的

<a href="<%=request.getContextPath() + response.encodeURL("/home.action")%>">URLRewriter 修正页面URL</a>
<a href="<c:url value="/home.action" />">URLRewriter 修正页面URL</a>
<s:a value="/home.action">urlRewriter</s:a>

? 4最后正则就不多说了.

  相关解决方案