Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java get-response状态代码告知请求是否应该在Spring MVC拦截器预处理方法中使用HTTP 404进行响应_Java_Spring_Spring Mvc_Interceptor - Fatal编程技术网

Java get-response状态代码告知请求是否应该在Spring MVC拦截器预处理方法中使用HTTP 404进行响应

Java get-response状态代码告知请求是否应该在Spring MVC拦截器预处理方法中使用HTTP 404进行响应,java,spring,spring-mvc,interceptor,Java,Spring,Spring Mvc,Interceptor,是否有可能获取响应状态代码,告知请求是否应该在SpringMVC拦截器中使用HTTP 404和preHandle方法进行响应 因为以下代码将导致将每个无效请求重定向到登录页面: public class SecurityInterceptor extends HandlerInterceptorAdapter { private static final Log LOG = LogFactory.getLog(SecurityInterceptor.class); @Overr

是否有可能获取响应状态代码,告知请求是否应该在SpringMVC拦截器中使用HTTP 404和preHandle方法进行响应

因为以下代码将导致将每个无效请求重定向到登录页面:

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;
    }

}

以下代码将重定向http请求,状态代码为:“临时302 http”。但是,如果负责“/signin”路径(或原始请求路径)的控制器不存在,这可能会生成HTTP 404。

不清楚您想要什么。应该发送404而不是重定向吗?是的,这就是我想要的。