<filter>
<filter-name>Filter</filter-name>
<filter-class>com.example.filter.Filter</filter-class>
</filter>
<filter-mapping>
<filter-name>Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<error-page>
<error-code>401</error-code>
<location>/errors/401.jsp</location>
</error-page>
response.addHeader("WWW-Authenticate", "BASIC realm=\"YOUR-REALM\"");
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);