如何在发送前更改响应

时间:2012-04-15 01:30:29

标签: java-ee glassfish

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

1 个答案:

答案 0 :(得分:0)

我尝试使用Filter with HttpServletResponseWrapper,但我的Filter在JAAS Basic HTTP Authentication之前从未被调用过。我通过下一个代码

解决了烦人的弹出窗口问题

在web.xml中:

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

的error.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>
相关问题