2

Hi I have a context and i have a mapping problem with this context. When I put this to my web.xml

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

I can only access like this.

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

but I wanna access like this

http://domain.com/sub-context

what should I do?

Edit: I saw that when i hit for http://domain.com/sub-context in browser it redirects me to http://domain.com/sub-context/ although i havent do anything special for that. Who is doing this. Weblogic?

4

1 回答 1

1

这是一种方法:

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

然后在重定向过滤器中:

  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);
  }

改编自此处:通过 google-app-engine 中的 web.xml 重定向

于 2013-01-05T16:49:30.027 回答