Spring webflow 如何在SpringWebFlow中处理CommonMultipartResolver中的SizeLimitExceedeException?

Spring webflow 如何在SpringWebFlow中处理CommonMultipartResolver中的SizeLimitExceedeException?,spring-webflow,spring-webflow-2,apache-commons-fileupload,Spring Webflow,Spring Webflow 2,Apache Commons Fileupload,我有以下情况。我有一个CommonsMultipartResolver bean,配置方式如下 <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="maxUploadSize" value="2100000" /> 我在SpringWebFlow视图状态jsp中有几个文件上传字

我有以下情况。我有一个CommonsMultipartResolver bean,配置方式如下

<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="2100000" />

我在SpringWebFlow视图状态jsp中有几个文件上传字段

如果文件低于限制,一切正常,但是如果文件超过2MB-s的限制,我必须在表单的绑定结果中添加验证错误

我的问题是,当超过文件限制时,多部分文件解析器抛出org.apache.commons.fileupload.FileUploadBase.SizeL-imitExceededException异常,我找不到在SpringWebFlow中捕获该异常并将我的FieldError添加到表单中的方法

我尝试使用transition标记的on exception属性,但如果我理解正确,它只适用于SpringWebFlow中抛出的异常

我还尝试在SpringMVC中使用SimpleMappingExceptionResolver,但我不想重定向到页面,我想处理这个异常

我还发现:

但是它是从1.0版开始的,我假设它已经被合并了,或者找到了更好的方法来处理这些情况

任何关于如何处理这一问题的想法都将不胜感激


谢谢。

在您的
SimpleMappingExceptionResolver
中,您应该能够覆盖
resolveException
方法,确定捕获的异常类型并进行适当处理

我在我们的项目中发现了一些旧代码,它们似乎是类似异常的解决方案

public class GeneralMappingExceptionResolver extends SimpleMappingExceptionResolver {

 @Override
 public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception exception) {

    if(exception instanceof MaxUploadSizeExceededException) {
        MaxUploadSizeExceededException maxe = (MaxUploadSizeExceededException)exception;
        String errorMessage = "Max filesize exceeded, please ensure filesize is too large.");
        HashMap<String, Object> model = new HashMap<String, Object>(2);
        model.put("errorMessage", errorMessage);
        return new ModelAndView("verification/psv/consent", model);
    } else {
        return super.resolveException(request, response, handler, exception); // Do whatever default behaviour is (ie throw to error page).
    }
}
公共类GeneralMappingExceptionResolver扩展了SimpleMappingExceptionResolver{
@凌驾
公共ModelAndView resolveException(HttpServletRequest请求、HttpServletResponse响应、对象处理程序、异常){
if(MaxUploadSizeExceedeException的异常实例){
MaxUploadSizeExceedeException maxe=(MaxUploadSizeExceedeException)异常;
String errorMessage=“超过最大文件大小,请确保文件大小过大。”);
HashMap模型=新的HashMap(2);
model.put(“errorMessage”,errorMessage);
返回新模型和视图(“验证/psv/同意”,模型);
}否则{
返回super.resolveException(请求、响应、处理程序、异常);//执行任何默认行为(即抛出到错误页)。
}
}
请注意,“verification/psv/Approve”是引发此异常的流程,它需要返回到该流程。我们只有一个具有文件上载的页面

显然,errorMessage只是传递到视图中的一个参数,因此需要像错误消息一样进行处理和显示。您可能还需要重新填充提交的任何其他表单字段。不过,希望这是一个正确的方向