2
応答ステータスコードを取得することは、リクエストがHTTP 404で返され、 Spring MVCインターセプタ。応答ステータスコードを取得すると、リクエストがHTTP MVCインターセプタpreHandleメソッド内でHTTP 404で応答する必要があるかどうかが示されます。
次のコードは、サインインページにすべての無効な要求をリダイレクトする結果となるので:「一時302 HTTP」:
public class SecurityInterceptor extends HandlerInterceptorAdapter {
private static final Log LOG = LogFactory.getLog(SecurityInterceptor.class);
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
LOG.info("Interceptor: Pre-handle");
HttpSession session = request.getSession();
String urlPath = request.getRequestURI();
String contextPath = request.getContextPath();
String relativePath = urlPath.replaceFirst(contextPath, "");
if (!relativePath.equals("/signin") && !relativePath.equals("/register")) {
if (session == null || session.getAttribute("curUser") == null) {
//redirect to signin
response.sendRedirect(contextPath + "/signin");
return false;
}
}
return true;
}
}
あなたが望むものは明確ではありません。リダイレクトの代わりに404を送信する必要がありますか? – zeroflagL
はい、そうです。 –