2
응답 상태 코드를 가져올 수 있는지 여부는 요청이 HTTP 내부에서 preHandle 메서드를 사용하여 HTTP 404로 응답해야하는지 여부를 알려줍니다. 스프링 MVC 인터셉터.get 응답 상태 코드는 요청이 Spring 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
네, 그게 내가 원하는거야. –