java - 在 web.xml [weblogic] 中映射根

标签 java mapping weblogic web.xml

您好,我有一个上下文,但我有一个与此上下文相关的映射问题。当我把它放到我的 web.xml 中时

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

我只能这样访问。

http://domain.com/sub-context/

但我想这样访问

http://domain.com/sub-context

我该怎么办?

编辑:当我点击 http://domain.com/sub-context 时我看到了在浏览器中,它将我重定向到 http://domain.com/sub-context/虽然我没有为此做任何特别的事情。谁在做这个。网络逻辑?

最佳答案

这是一种方法:

  <filter-mapping>
    <filter-name>RedirectFilter</filter-name>
    <url-pattern>/sub-context</url-pattern>
  </filter-mapping>

然后在 RedirectFilter 中:

  public void doFilter(ServletRequest req, ServletResponse resp, FilterChain filterChain)
  throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest)req;
    HttpServletResponse response = (HttpServletResponse)resp;
    response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
    String redirectURL = "http://domain.com/sub-context/";
    response.setHeader("Location", redirectURL);
  }

改编自此处:redirect through web.xml in google-app-engine

关于java - 在 web.xml [weblogic] 中映射根,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14173874/

相关文章:

java - SOAP 使用适配器休息服务

qt - 将坐标映射到项目未按预期工作

weblogic - Internet Explorer 中 Weblogic 的 SSL 证书错误

java - 如何将 WebLogic Server 配置到现有 Eclipse

java - 将 Objective-C 编译为 Java

java - 从适配器替换时找不到 fragment ID 的 View

java - ModelMapper:来自空对象的 Incorect 属性映射

ubuntu - 如何将在特定端口号上运行的服务映射到 Ubuntu 上的别名?

java - 将大型单体应用程序拆分为 2 个应用程序有什么好处?

Java swing,无法让文本字段按预期显示