UrlRewriteFilter和Struts2的生成伪静态页面

1、pom.xml文件增加依赖

<!-- url重写 -->
	<dependency>
	    <groupId>org.tuckey</groupId>
	    <artifactId>urlrewritefilter</artifactId>
	    <version>4.0.3</version>
	</dependency>

2、web.xml文件增加过滤器

<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>

    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>struts2</filter-name>  
        <url-pattern>*.action</url-pattern>  
        <dispatcher>REQUEST</dispatcher>      
        <dispatcher>FORWARD</dispatcher>    
        <dispatcher>INCLUDE</dispatcher>   
    </filter-mapping>

3、WEB-INF/urlrewrite.xml配置如下

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 4.0//EN"
        "http://www.tuckey.org/res/dtds/urlrewrite4.0.dtd">
        
<urlrewrite>

    <rule>
        <from>/validatecodeverify.html</from>
        <to>/validatecodeverify.action</to>
    </rule>

	<rule>
		<from>/validatecode.html</from>
		<to>/validatecode.action</to>
	</rule>
</urlrewrite>

4、页面访问配置地址

<div id="verifyCode" >
                    <p>
                    	<span class="regtlx">验 证 码</span>
                        <input class="inp inw" id="validatecode" maxlength="5" name="validatecode" size="2" type="text">
                        <img align="absmiddle" onclick="refreshValidatecode(); return false" name="vcodeImg" id="vcodeImg" style="cursor: pointer; height: 32px;" src="${ctx}/validatecode.html?temp=123i1knr04o">
                        <a onclick="refreshValidatecode(); return false" href="javascript:void(0)" class="f12">看不清?</a>
                    	<span id="validatecode_Tip"></span> 
                    </p>
                    <script type="text/javascript">
                        function refreshValidatecode(){
                           document.getElementById('vcodeImg').src='${ctx}/validatecode.html?temp=123'+ (new Date().getTime().toString(36));
                        }
                    </script>
                </div>

5、参考文档

http://tuckey.org/urlrewrite/#documentation 

你可能感兴趣的:(UrlRewriteFilter和Struts2的生成伪静态页面)