我希望有人能够指出,我在这里会错。 I m试图制造一个简单的过滤器,它做的是Paul Tuckey s URLRewriteFilter,但只做我需要做的事情。
我无法阻止它回到原来的《世界投资倡议》。 我在《URLRewriteFilter法典》上宣布了出来,似乎正在做基本上相同的事情。 我的过滤代码如下:
public static final String dispatcherURI = "/Dispatcher?q=";
public void doFilter(final ServletRequest request, final ServletResponse response,
final FilterChain chain)
throws IOException, ServletException {
final HttpServletRequest rq = (HttpServletRequest)request;
final HttpServletResponseWrapper rsw =
new HttpServletResponseWrapper((HttpServletResponse)response);
final String uri = rq.getRequestURI();
if (uriIsDispatchable(uri)) {
final String forwardPath = dispatcherURI+uri;
rq.getRequestDispatcher(forwardPath).forward(rq, rsw);
LOG.info("Forward From: "+uri+", To: "+forwardPath);
}
else {
try { chain.doFilter(request, response); }
catch (Exception e) {
LOG.error(e);
throw new RuntimeException(e);
}
}
}
// checks URI against an ArrayList of URIs that should be ignored.
private static boolean uriIsDispatchable (final String uri) {
boolean result = true;
for (String i : ApplicationValues.uriIgnore) {
if (uri.indexOf(i) == 0) {
result = false;
break;
}
}
return result;
}
Here s the filter entry in web.xml
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>myapp.filter.URLRewrite</filter-class>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Some notes on the code: A URI like /home should be forwarded to a dispatcher servlet like so: /Dispatcher?q=/home the dispatcher servlet then determines what code to execute based on what s in the query string.
过滤器正确地忽视了“uriIgnore”ArrayList(包括分机/分机)中的URIs,但前方在家留宿。 为了完整起见,本文摘录了在上述各种可分的方法中检索的uriIgnore ArrayList的内容:
public static final List<String> uriIgnore = new ArrayList<String>(4);
static {
uriIgnore.add("/Dispatcher");
uriIgnore.add("/netbeans-tomcat-status-test");
uriIgnore.add("/resources");
uriIgnore.add("/robots.txt");
}
另外,我跑了最新的Tomcat 6号车.在阿帕奇。
感谢任何帮助。 感谢。