java web指定主页

正常情况下主页是在web.xml里面配置欢迎页面,可以加个过滤器重定向就可以:

public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) res;
        
        String effectivePath = request.getRequestURI().substring(request.getContextPath().length());
        if (effectivePath.equals("/")) {
                //访问项目的根路径
            response.sendRedirect("/destination.jsp");
            return;
        }
        
        chain.doFilter(request, response);
    }

 

posted @ 2019-01-24 17:03  护花使者  Views(247)  Comments(0Edit  收藏  举报