在web.xml中映射根[weblogic]

时间:2013-01-05 16:35:02

标签: 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/,尽管我没有做任何特别的事情。谁在做这件事。的Weblogic?

1 个答案:

答案 0 :(得分:1)

这是一种方式:

  <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