HttpServletResponse重定向到页面而不显示它

时间:2019-03-21 16:33:57

标签: servlets

我正在尝试从应用程序重定向到登录页面。 我注意到在网络流量中,针对该页面返回的登录地址未在导航器级别显示( 看到图片作为附件)

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
        System.out.println("doFilter");
        HttpServletRequest httpRequest = (HttpServletRequest) request;
        HttpServletResponse httpResponse = (HttpServletResponse) response;

        Utilisateur user = (Utilisateur) httpRequest.getSession().getAttribute(ConstantesPrixCarb.ATT_USER);
        System.out.println(httpRequest.getRequestURI());
        if (user == null) {
            httpResponse.sendRedirect(System.getProperty("url.login.page"));
            return;

        } else {
            chain.doFilter(request, response);
        }

    }

enter image description here

0 个答案:

没有答案