0

是否可以拦截向客户端发送响应,并在最终发送修改后的响应?我想从基本身份验证响应中删除“WWW-Authenticate”标头,或者在错误的身份验证情况下将错误代码从 401 更改为 403。PS我有同样的问题:http ://www.java.net/forum/topic/glassfish/glassfish/suppress-www-authenticate-header-if-basic-auth-fails

4

1 回答 1

1

我尝试将过滤器与 HttpServletResponseWrapper 一起使用,但在 JAAS 基本 HTTP 身份验证之前从未调用过我的过滤器。我通过下一个代码解决了烦人的弹出窗口的问题

在 web.xml 中:

<error-page>
    <error-code>401</error-code>
    <location>/error.jsp</location>
</error-page>

错误.jsp:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>
        <%
        int status = response.getStatus();
        if (status == 401) {
            response.setStatus(403);
        }
        %>
    </body>
</html>
于 2012-04-16T16:30:08.843 回答