urlrewrite 配置

阅读更多

    在进行链接伪静态时用到了urlrewrite,一个开源的jar包,配置使用:

首先下载jar包导入,下载地址:http://code.google.com/p/urlrewritefilter/downloads/list ,
在web.xml 加入UrlRewriteFilter

        UrlRewriteFilter
        org.tuckey.web.filters.urlrewrite.UrlRewriteFilter
        
                logLevel
            WARN
        
    
    
        UrlRewriteFilter
        /*
    


  可选的初始化参数 :
  confReloadCheckInterval:间隔冲洗加载时间秒。调试时用这个。
  confPath :制定配置文件,不加默认(/WEB-INF/urlrewrite.xml)
  statusPath:查看urlrewrite配置的详细,默认/rewrite-status。若在  /a/* 则是:/a/rewrite-status
  statusEnabled: 若为false,则 statuspath无效,默认true
  statusEnabledOnHosts,allowConfSwapViaHttp,modRewriteConf,modRewriteConfText

  然后urlrewrite.xml 中配置,下面这个是jar包中自带的配置和说明:
 
  



  
            /some/old/page.html
            /very/new/page.html
        
	

   
        
            /some/olddir/(.*)
            /very/newdir/$1
        

    
        
	    简化url
	    /products/1234 will be passed on to /products/index.jsp?product_id=1234 without the user noticing.
            /products/([0-9]+)
            /products/index.jsp?product_id=$1
        
        
	    will pass the request for /some/page.html on to /some/page-for-old-browsers.html only for older
    browsers whose user agent srtings match Mozilla/1, Mozilla/2, Mozilla/3 or Mozilla/4

            Mozilla/[1-4]
            /some/page.html
            /some/page-for-old-browsers.html
        
   
        
            Mozilla/[1-4]
            moz
        



其中rule 还可以这样
   
        test Rule 
        this is a  test normalRule.
        8080
        1
        12
        2010

        
         /some/olddir/(.*)
         /very/newdir/$1
    


condition 所支持的type类型,可以在:TypeConverter类中有:
 public String getType() {
        switch (type) {

            case TYPE_TIME:
                return "time";
            case TYPE_TIME_YEAR:
                return "year";
            case TYPE_TIME_MONTH:
                return "month";
            case TYPE_TIME_DAY_OF_MONTH:
                return "dayofmonth";
            case TYPE_TIME_DAY_OF_WEEK:
                return "dayofweek";

            case TYPE_TIME_AMPM:
                return "ampm";
            case TYPE_TIME_HOUR_OF_DAY:
                return "hourofday";
            case TYPE_TIME_MINUTE:
                return "minute";
            case TYPE_TIME_SECOND:
                return "second";
            case TYPE_TIME_MILLISECOND:
                return "millisecond";

            case TYPE_ATTRIBUTE:
                return "attribute";
            case TYPE_AUTH_TYPE:
                return "auth-type";
            case TYPE_CHARACTER_ENCODING:
                return "character-encoding";
            case TYPE_CONTENT_LENGTH:
                return "content-length";
            case TYPE_CONTENT_TYPE:
                return "content-type";

            case TYPE_CONTEXT_PATH:
                return "context-path";
            case TYPE_COOKIE:
                return "cookie";
            case TYPE_HEADER:
                return "header";
            case TYPE_LOCAL_PORT:
                return "local-port";
            case TYPE_METHOD:
                return "method";
            case TYPE_PARAMETER:
                return "parameter";

            case TYPE_PATH_INFO:
                return "path-info";
            case TYPE_PATH_TRANSLATED:
                return "path-translated";
            case TYPE_PROTOCOL:
                return "protocol";
            case TYPE_QUERY_STRING:
                return "query-string";
            case TYPE_REMOTE_ADDR:
                return "remote-addr";

            case TYPE_REMOTE_HOST:
                return "remote-host";
            case TYPE_REMOTE_USER:
                return "remote-user";
            case TYPE_REQUESTED_SESSION_ID:
                return "requested-session-id";
            case TYPE_REQUEST_URI:
                return "request-uri";
            case TYPE_REQUEST_URL:
                return "request-url";

            case TYPE_SESSION_ATTRIBUTE:
                return "session-attribute";
            case TYPE_SESSION_IS_NEW:
                return "session-isnew";
            case TYPE_SERVER_PORT:
                return "port";
            case TYPE_SERVER_NAME:
                return "server-name";
            case TYPE_SCHEME:
                return "scheme";

            case TYPE_USER_IN_ROLE:
                return "user-in-role";
            case TYPE_EXCEPTION:
                return "exception";
            default:
                return "";
        }
    }


对应的method中的参数必须是一下几种。
{ServletRequest.class, ServletResponse.class},
{ServletRequest.class},
{ServletResponse.class},
{HttpServletRequest.class, HttpServletResponse.class},
{HttpServletRequest.class},
{HttpServletResponse.class}

在类Run中用到反射来验证方法是否存在,反射时默认的参数是以上几种。
在过滤是符合规则 会执行run中对应的方法然后在转向真正的url。

好了,ok。

你可能感兴趣的:(Scheme,XML,JSP,Web,HTML)