1

我编写了一个实现HandlerExceptionResolverspring 的类来处理MaxUploadSizeExceededException异常,因为我们允许上传最大 25MB 大小。我已经在 servletcontext 中注册了这个类,如下所示:

<bean id="uploadingFileSizeExceeds" 
  class="com.puresafety.health.ui.web.demographics.controllers.FileSizeExceedsMaxLimitHandler" >
</bean>

FileSizeExceedsMaxLimitHandler

public class FileSizeExceedsMaxLimitHandler implements HandlerExceptionResolver {
    private final static Log logger = LogFactory
            .getLog(FileSizeExceedsMaxLimitHandler.class);

    public ModelAndView resolveException(HttpServletRequest request,
            HttpServletResponse response, Object handler, Exception ex) {
        logger.debug("FileSizeExceedsMaxLimitHandler.resolveException: Control is coming here because uploading file size is exceeding max allowed limit.");
        if (ex instanceof MaxUploadSizeExceededException
                && request.getPathInfo().equals(
                        "/demographicsPhoto/uploadimagefile")) {
            logger.debug("FileSizeExceedsMaxLimitHandler.resolveException: MaxUploadSizeExceededException occurred");
            request.setAttribute("ALERTMESSAGE",
                    "The image size is exceeding the allowed limit.");
            ImageUploadForm imageUploadForm = new ImageUploadForm();
            Map<String, Object> model = new HashMap<String, Object>();
            model.put("imageUploadForm", imageUploadForm);
            return new ModelAndView("demographics/uploadEmployeeImage", model);
        }
        return new ModelAndView("base/error/error404");
    }
}

它在我的本地成功地捕获了异常,但在我们的集群 QA 环境中不起作用,即控制不会转到此类中的方法 resolveException。

我在这里缺少什么。提前致谢!

4

0 回答 0