⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 urlrewritefilter.java

📁 urlrewritefilter-2.6-src.zip
💻 JAVA
字号:
/**
 * Copyright (c) 2005, Paul Tuckey
 * All rights reserved.
 *
 * Each copy or derived work must preserve the copyright notice and this
 * notice unmodified.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */
package org.tuckey.web.filters.urlrewrite;

import org.tuckey.web.filters.urlrewrite.utils.Log;
import org.tuckey.web.filters.urlrewrite.utils.NumberUtils;
import org.tuckey.web.filters.urlrewrite.utils.StringUtils;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Date;

/**
 * Based on the popular and very useful mod_rewrite for apache, UrlRewriteFilter is a Java Web Filter for any J2EE
 * compliant web application server (such as Resin or Tomcat), which allows you to rewrite URLs before they get to your
 * code. It is a very powerful tool just like Apache's mod_rewrite.
 * <p/>
 * The main things it is used for are:
 * <p/>
 * <ul>
 * <li>URL Tidyness - keep URLs tidy irrespective of the underlying technology (JSPs, servlets, struts etc).</li>
 * <li>Browser Detection - Allows you to rewrite URLs based on request HTTP headers (such as "user-agent").</li>
 * <li>Date based rewriting - Allows you to forward or redirect to other URL's based on the date/time.</li>
 * </ul>
 * UrlRewriteFilter uses an xml file, called urlrewrite.xml (lives in the WEB-INF directory), for configuration. Most
 * parameters can be Perl5 style Regular Expressions. This makes it very powerful indeed.
 * <p/>
 * Special thanks to all those who gave patches/feedback especially Vineet Kumar.
 * <p/>
 * Thanks also to Ralf S. Engelschall (www.engelschall.com) the inventor of mod_rewrite
 * <p/>
 * <p/>
 * <p/>
 * todo: ability to test new conf without having to reload, via status page
 * todo: ability to have no from, just conditions matches
 * todo: user in role throw 403 if no match?
 * todo: ability to set default-to-type on <urlrewrite> level of conf file for conf files full of redirects
 * todo: allow condition matching on get-param or post-param as well as just parameter
 * todo: store list of robots and hide jsessionid when a robot also have condition
 * todo: allow mounting of packages from /xxxyyy/aaa.gif to org.tuckey.xxx.static."aaa.gif" http://wiki.opensymphony.com/pages/viewpage.action?pageId=4476
 * todo: think about a simple matching mode (ruletype wildcard) eg,
 * http://blah.com/some_context/dir/a-file.jsp;jsess=asasdsdas?someid=1#godown
 * The regexps etc should match on
 * ie,
 * <condition type="param" name="someid">1</condition>
 * <from>/dir/*.jsp</from>
 * <to>/anotherdir/$1.jsp</to>
 * or for regexp
 * <rule type="regexp">
 * <condition type="param" name="someid">1</condition>
 * <from>/dir/[a-z]-[a-z].jsp</from>
 * <to>/anotherdir/$1-$2.jsp</to>
 * </rule>
 * <p/>
 * todo: <on-startup><run </on-startup> <on-shutdown> <run </on-shutdown> will conflict with run in a rule init?
 * todo: handle exceptions, condition exception regexp match name
 * <p/>
 * todo: instanceof in urlrewrite filter conditions
 * <p/>
 * todo: When initially hitting my inventory page the links are in the format:
 * http://houston.freewaytrucks.com/fmi/xsl/browserecord-grid-flash.xsl;jsessionid=10876ED05390E6D24235ACC70ABCF977?-lay=Web+Inventory&-recid=11891&-find=-find
 * Could I write a rule using UrlRewrite that removes ;jsessionid=xxxxx

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -