您好,我有一个上下文,但我有一个与此上下文相关的映射问题。当我把它放到我的 web.xml 中时
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
我只能这样访问。
但我想这样访问
我该怎么办?
编辑:当我点击 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);
}
关于java - 在 web.xml [weblogic] 中映射根,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14173874/