【问题标题】:Redirect from index page in Spring and Tomcat从 Spring 和 Tomcat 中的索引页面重定向
【发布时间】:2011-04-20 08:40:01
【问题描述】:

我有一个 Spring 应用程序,它在 Tomcat 上运行,地址为:http://example.com/foo/

DisplatcherServlet 映射到 app/*,例如 index 页面为:

http://example.com/foo/app/index.html

之所以如此,是因为我有其他 servlet(用于 HttpRequestHandlers),例如映射到服务/*。这种方案使用起来很方便,因为这样app/和service/可以有不同的安全设置。

我想要的是http://example.com/foo 重定向到http://example.com/foo/app/index.html

我如何做到这一点?

【问题讨论】:

    标签: spring tomcat redirect


    【解决方案1】:

    在您的 web.xml 中,您可以定义一个欢迎文件,在导航到应用的根目录时可以看到:

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    

    然后你可以创建一个小的 index.jsp 来重定向到你想要的位置:

    <% response.sendRedirect("app/index.html"); %>
    

    【讨论】:

      【解决方案2】:

      您可以将(tuckey) Url Rewrite Filter 添加到您的应用程序中。

      它为您提供了在您的应用程序中定义 URL 重写规则的功能(传入和传出)。

      因此,您可以为 \ 定义重写规则,将其重写为 myApplication.startpage - 或其他内容。

      @see: http://mattgivney.blogspot.com/2010/07/how-to-url-rewrite-in-spring-mvc.html - 一个简短的例子

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-03-10
        • 2021-04-28
        • 1970-01-01
        • 2016-08-30
        • 2020-11-05
        • 2018-03-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多