我正在开发图像上传系统。我使用 CommonsMultipartResolver 设置 maxUploadSize。当我尝试上传超过最大尺寸的图像文件时,会发生 MaxUploadSizeExccededException。但所有图像文件都已发送,尽管它有超过 1G 字节。
如何关闭套接字?我想在发生此异常时关闭套接字。
谢谢你。
Controller .xml
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" >
<property name="maxUploadSize" value="100" />
</bean>
Controller .java
@RequestMapping(value="upload/", method={RequestMethod.POST})
public void uploadImage( ThumbnailRequestParams thumbnailRequestParams
, HttpServletResponse response) throws IOException{
uploadImage(thumbnailRequestParams, response);
}
form.html
<form action="upload/" method="post" NAME="testForm" ENCTYPE="multipart/form-data">
<input type="file" id="file" name="file"/><br/>
idName : <input type="text" id="idName" name="idName"/><br/>
<input type="submit" value="upload"/>
</form>
最佳答案
您不应抛出 IOException
,而应捕获 MaxUploadSizeExceededExeception
。在 catch block 中,您可以关闭套接字。
关于java - 发生 MaxUploadSizeExceededException 时如何关闭套接字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7106669/