投稿 评论 顶部

java 实现伪静态地址

佚名 网络安全

要实现java的伪静态地址访问,我们需要用的urlrewrite的jar包

1,先下载urlrewrite.jar包,下载地址:http://download.csdn.net/detail/xiangrong530/43096462

,配置urlrewrite.xml配置文件,放入到 WEB-INF根目录下面

?

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

<urlrewrite>
?<!-- 处理参数的伪地址: 首先你要知道这个地址需要带多少个参数,
? 我以登录为例:longin!index.htm?email_mobile=xx&pwd=xx&yzname=xxx
? 我们可以这样访问:longin/index.htm/xx/xx/xxx
? -->
?<rule>
??????? <from>^/(.+)/(.+)/(.+)/(.+)/(.+)</from>
??????? <to type="forward">/$1!$2.htm?email_mobile=$3&amp;pwd=$4&amp;yzname=$5</to>
??? </rule>
??? <!--
??? ?这个配置要放在后面,因为它可以识别所有的请求
??? ?只把用!符号请求换成斜杆: 比如:login!index.htm 换成login/index,要接参数的话 login/index?name=xxx&pwd=xx
??? -->
?<rule>
??????? <from>^/(.+)/(.+)</from>
??????? <to type="forward">/$1!$2.htm</to>
??? </rule>
?
</urlrewrite>

?2,web.xml 配置修改

首先要把urlrewrite.xml导入进来

<context-param>
??<param-name>con</param-name>
??<param-value>/WEB-INF/urlrewrite.xml</param-value>
?</context-param>
?<filter>
??<filter-name>UrlRewriteFilter</filter-name>
??<filter-class>
???org.tuckey.web.filters.urlrewrite.UrlRewriteFilter
??</filter-class>
??<init-param>
???? <param-name>logLevel</param-name>
???? <param-value>debug</param-value>
??? </init-param>
?</filter>
?<filter-mapping>
??<filter-name>UrlRewriteFilter</filter-name>
??<url-pattern>/*</url-pattern>
?</filter-mapping>

?

其次要把过滤器和struts请求修改成下

加载过滤器

<filter>
??<filter-name>AuthFilter</filter-name>
??<filter-class>com.payfee.common.AuthFilter</filter-class>
??
??<init-param>
???<param-name>loginPage</param-name>
???<param-value>/index.ftl</param-value>
??</init-param>
??????????????????????
?</filter>
?
?<filter-mapping>
??<filter-name>AuthFilter</filter-name>
??<url-pattern>*.htm</url-pattern>
??<dispatcher>FORWARD</dispatcher>
??<dispatcher>REQUEST</dispatcher>
?</filter-mapping>

过滤器如果不加载红色的字的话,就不会经过过滤器

?

加载struts2架构拦截器

<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>*.htm</url-pattern>

配置URL地址转换拦截器的转发类型

<dispatcher>FORWARD</dispatcher>

<dispatcher>REQUEST</dispatcher>

</filter-mapping>

struts拦截器如果不加载红色的字的话,就不会经过action

基本上面的配置就是这样的.大家仔细的看看urlrewrite.xml,

我已经很详细的写好了怎么去访问!