web.xml ファイルでカスタム エラー ページを構成しましたが、ページで参照されている画像が壊れたリンクとして表示されます。
カスタム エラー ページは単純な html ページです。
<!DOCTYPE html>
<html><head>
<meta charset="UTF-8"><title>401 Error</title></head>
<body>
<p style="font-size: 200%; text-align: center">HTTP Error 401: Not authorized to view sensitive data.<br/>
<img src="NoAccessImage.png" alt="401Error"><br/>
You must log in before viewing the requested page.</p>
</body></html>
このページは、参照する画像ファイルとともにエラー フォルダーに保存されます。最初にログインせずに保護されたコンテンツを表示しようとすると、認証フィルターが 401 エラーをスローするために使用され、ページが表示されます。しかし、参照された画像が見つかりません。ファイルを Web ブラウザーにドラッグするだけで正しく表示されるので、これは文脈の問題だと思いました。img src タグを に変更しようとしました"/error/NoAccessImage.png"
が、結果はありませんでした。
関連する AuthenticationFilter コードは次のとおりです。
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
try {
boolean authorized = false;
HttpServletRequest r = (HttpServletRequest) request;
HttpSession session = ((HttpServletRequest)request).getSession(false);
String uri = r.getRequestURI();
if(uri.indexOf("/Login")>0) {
chain.doFilter(request, response);
return;
}
if (session != null) {
String school = (String) session.getAttribute("school");
if(school != null && school.length()>0 ) {
authorized = (school.equals(getURISchool(uri)));
}
}
if (authorized) {
chain.doFilter(request, response);
return;
} else {
((HttpServletResponse) response).sendError(401, "You must log in to view the schedule.");
}
} catch (IOException io) {
System.out.println("IOException raised in AuthenticationFilter");
}
}