首页 > 学院 > 开发设计 > 正文

urlrewrite结合struts2

2019-11-15 00:34:19
字体:
来源:转载
供稿:网友
urlrewrite结合struts2

1、下载jar包 http://tuckey.org/urlrewrite/

2、web.xml配置

    <!-- url重写begin -->    <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>WARN</param-value>        </init-param>    </filter>    <filter-mapping>        <filter-name>UrlRewriteFilter</filter-name>        <url-pattern>/*</url-pattern>    </filter-mapping>    <!-- url重写end -->        <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>*.shtml</url-pattern>        <dispatcher>REQUEST</dispatcher>           <dispatcher>FORWARD</dispatcher>             </filter-mapping>

3、新建xml文件: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"><!--    Configuration file for UrlRewriteFilter    http://tuckey.org/urlrewrite/--><urlrewrite>         <rule>        <note>            The rule means that requests to /test/status/ will be redirected to /rewrite-status            the url will be rewritten.        </note>        <from>^/vweb/view/index/-([0-9]+)$</from>        <to>/vweb/view/index.shtml?_id=$1</to>    </rule></urlrewrite>

类似于:/vweb/view/index-1 这样的请求会被转译成:/vweb/view/index.shtml?_id=1


上一篇:Spring MVC

下一篇:java基础——集合

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表