【问题标题】:HttpServletResponse sendRedirect to another app in the same app serverHttpServletResponse sendRedirect 到同一应用服务器中的另一个应用
【发布时间】:2015-06-26 12:42:42
【问题描述】:

我的应用服务器中部署了两个应用。假设他们有以下网址

  1. localhost:9080/App1
  2. localhost:9080/App2

我在 App2 中有一个过滤器,它可以捕获某个请求。当我收到这个请求时,我想将它转发到 App2 中的一个 url。

我知道这可以通过

response.sendRedirect("http://somewhere");

但是如果我不想在我的代码中硬编码“localhost:9080”怎么办,因为这将是动态的并且稍后会改变。

我该怎么做?

【问题讨论】:

    标签: servlets url-redirection


    【解决方案1】:

    你试过了吗

    response.sendRedirect("/relativePathToRedirect");
    

    允许相对重定向 AFAIK

    请参考

    http://en.wikipedia.org/wiki/HTTP_location

    Is a 302 Redirect to relative URL valid, or invalid?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-25
      • 2011-02-14
      • 2015-05-30
      • 2018-03-21
      • 1970-01-01
      • 2012-02-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多