重定向对Tomcat 6.0中子目录​​的所有请求 [英] Redirect all requests for a subdirectory in Tomcat 6.0

查看:76
本文介绍了重定向对Tomcat 6.0中子目录​​的所有请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在桌面上运行本地Tomcat 6.0服务器.

I'm running a local Tomcat 6.0 server on my desktop.

我正在尝试重定向与 http://localhost:8080/RedirectDirectory/abc/efg/morejunk 到单个JSP页面.

I'm trying to redirect any and all requests matching http://localhost:8080/RedirectDirectory/abc/efg/morejunk to a single JSP page.

在RedirectDirectory项目的web.xml中,我拥有

In my RedirectDirectory project's web.xml I have

<servlet>
<servlet-name>IOPRedirect</servlet-name>
<jsp-file>/RedirectDirectory/filetree.jsp</jsp-file>
</servlet>

<servlet-mapping>
<servlet-name>IOPRedirect</servlet-name>
<url-pattern>/RedirectDirectory/*</url-pattern>
</servlet-mapping>

无论该目录是否存在,我真的希望它转到该JSP.

I would really like it to go to that JSP whether the directory exists or not.

我以为这是怎么做的,但我想不是.

I thought this is how to do it, but I guess not.

有什么想法吗?

谢谢

推荐答案

在解决此类问题时,我通常使用UrlRewriteFilter.

I usually use the UrlRewriteFilter when solving problems like this.

  1. 下载并将urlrewrite.jar添加到您的类路径中(WEB-INF/lib )
  2. 将以下内容添加到您的WEB-INF/web.xml:
  1. Download and add the urlrewrite.jar to your classpath (WEB-INF/lib)
  2. Add the following to your WEB-INF/web.xml:



    <filter>
        <filter-name>UrlRewriteFilter</filter-name>
        <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>UrlRewriteFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

  1. 编辑WEB-INF/urlrewrite.xml并添加以下内容:



    <rule>
        <from>^/RedirectDirectory/(.*)$</from>
        <to>/RedirectDirectory/filetree.jsp</to>
    </rule>

在项目中具有UrlRewriteFilter可以非常方便地解决许多常见问题,例如设置缓存头,规范的主机名,在某些URL上使用https等.

Having UrlRewriteFilter in your project is very handy for solving a lot of common problems like setting cache headers, canonical hostnames, forcing https on certain urls etc.

这篇关于重定向对Tomcat 6.0中子目录​​的所有请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆