urlrewrite 配置
在进行链接伪静态时用到了urlrewrite,一个开源的jar包,配置使用:
首先下载jar包导入,下载地址:http://code.google.com/p/urlrewritefilter/downloads/list ,
在web.xml 加入UrlRewriteFilter
<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>
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.2//EN" "http://tuckey.org/res/dtds/urlrewrite3.2.dtd"><!-- Configuration file for UrlRewriteFilter http://tuckey.org/urlrewrite/--><urlrewrite> <rule> <from>/some/old/page.html</from> <to type="redirect">/very/new/page.html</to> </rule> <!-- Redirect a directory--> <rule> <from>/some/olddir/(.*)</from> <to type="redirect">/very/newdir/$1</to> </rule> <!-- Clean a url--> <rule> <name>简化url</name> <note>/products/1234 will be passed on to /products/index.jsp?product_id=1234 without the user noticing.</note> <from>/products/([0-9]+)</from> <to>/products/index.jsp?product_id=$1</to> </rule> <rule> <note>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</note> <condition name="user-agent">Mozilla/[1-4]</condition> <from>/some/page.html</from> <to>/some/page-for-old-browsers.html</to> </rule> <!-- Centralised browser detection --> <rule> <condition name="user-agent">Mozilla/[1-4]</condition> <set type="request" name="browser">moz</set> </rule></urlrewrite>
<rule> <name>test Rule </name> <note>this is a test normalRule.</note> <condition type="local-port">8080</condition> <condition type="dayofweek">1</condition> <condition type="ampm" operator="less">12</condition> <condition type="year" operator="greaterorequal">2010</condition> <run method="justRun" jsonhandler="true"/> <from>/some/olddir/(.*)</from> <to type="redirect">/very/newdir/$1</to> </rule>
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 ""; } }