I have a Java EE project with web services protected by web container authentication. (HTTP-basic) (we can say in this context: the web services are servlets) A would like to modify the servlets response header. Using servlet filter is not a good solution because I want to access the response object in the event of the user authentication failed. (in this case the servlet filter does not run, because the container does not invoke it)
The reason is, I want to change the HTTP status codes 401 and 403. That is because the client are distributed by Web Start and I do not want to allow the javaws to modify my client application request headers.
There is a ServletRequestListener listener, but it is not right for me, because I want to access the response object, not the request.
Thanks.
Just copy entend answer
In 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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With