简体   繁体   中英

Mapping root in web.xml [weblogic]

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?

Here is one way:

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

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

Adapted from here: redirect through web.xml in google-app-engine

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM