我编写了一个实现spring HandlerExceptionResolver
的类来处理MaxUploadSizeExceededException
expception,因为我们允许上传最大25MB的大小。我在servletcontext中注册了这个类,如下所示:
<bean id="uploadingFileSizeExceeds"
class="com.puresafety.health.ui.web.demographics.controllers.FileSizeExceedsMaxLimitHandler" >
</bean>
Class 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");
}
}
它在我的本地成功捕获异常但在我们的Clustered QA环境中没有工作,即控制不会在此类中使用resolveException方法。
我在这里缺少什么。 提前致谢!