Spring @ExceptionHandler方法未重定向到返回视图
Spring @ExceptionHandler方法未重定向到返回视图,spring,spring-mvc,controller,hybris,Spring,Spring Mvc,Controller,Hybris,我对@ControllerAdvice中的@ExceptionHandler方法有问题 我的方法在发生异常时被调用,但从未重新发布到通过此方法返回的站点。我试图返回ModelANdView、RedirectView或String,但始终无法正常工作 这是我的方法的实际代码: public static final String REFERER_HEADER = "Referer"; public static final String REDIRECT = "redirect:"; @
我对@ControllerAdvice中的@ExceptionHandler方法有问题 我的方法在发生异常时被调用,但从未重新发布到通过此方法返回的站点。我试图返回ModelANdView、RedirectView或String,但始终无法正常工作 这是我的方法的实际代码:
public static final String REFERER_HEADER = "Referer";
public static final String REDIRECT = "redirect:";
@ExceptionHandler(value = MaxUploadSizeExceededException.class)
public RedirectView maxUploadSizeExceededExceptionHandler(MaxUploadSizeExceededException e,
HttpServletRequest request,HttpServletResponse response) {
String sourcePage = request.getHeader(REFERER_HEADER);
RedirectView rw = new RedirectView(REDIRECT + sourcePage);
return rw;
}
但正如我所说,这是不正确的。在浏览器中,当出现异常时,我将停留在页面上您可以尝试使用其中一个吗
public static final String REFERER_HEADER = "Referer";
public static final String FORWARD_PREFIX = "forward:";
@ExceptionHandler(value = MaxUploadSizeExceededException.class)
public String maxUploadSizeExceededExceptionHandler(MaxUploadSizeExceededException e,
HttpServletRequest request,HttpServletResponse response) {
String sourcePage = request.getHeader(REFERER_HEADER); // Assuming you have sourcePage eg : "/pageURL"
return FORWARD_PREFIX + sourcePage;
}
或
但是我不确定…你能试一下其中一个吗
public static final String REFERER_HEADER = "Referer";
public static final String FORWARD_PREFIX = "forward:";
@ExceptionHandler(value = MaxUploadSizeExceededException.class)
public String maxUploadSizeExceededExceptionHandler(MaxUploadSizeExceededException e,
HttpServletRequest request,HttpServletResponse response) {
String sourcePage = request.getHeader(REFERER_HEADER); // Assuming you have sourcePage eg : "/pageURL"
return FORWARD_PREFIX + sourcePage;
}
或
但是我不确定……我知道那是很久以前的事了,但是你能找到解决办法吗?我知道那是很久以前的事了,但是你能找到解决办法吗?