Add the following configuration <!-- springmvc upload files in XML, you need to configure Multipartresolver processor --> <bean id= "Multipartresolver" class= "org.springframework.web.multipart.commons. commonsmultipartresolver "> <property name= "defaultencoding" value= "UTF-8"/> <!-- Specifies that the total size of uploaded files cannot exceed 200KB. Note that the Maxuploadsize property is not restricted to a single file, but to the capacity of all files --> <property name= "Maxuploadsize" value= "200000"/> <!--The Resolvelazily property is enabled to postpone file resolution so that the file size exception is captured in uploadcontroller --> <property name= "Resolvelazily" value= "true"/> &Nbsp; </bean>
Action to add the following processing
@Controller
public class testaction{
@RequestMapping (value = "/encoder/importencoder")
@ResponseBody
Public Modelandview Importencoder (multipartfile encoderfile, Integer unitid) {
Code omitted
}
/***
* * Exception Handling
***/
@ExceptionHandler (Exception.class)
Public @ResponseBody Modelandview Exceptionhandler (Exception exceededexception) {
ActionResult result = new ActionResult (false);
if (Validateutil.isnotnull (exceededexception) && (Exceededexception.getcause () instanceof Maxuploadsizeexceededexception)) {
Result.setmessage ("file import exceeds the + constparamencoder.getfaceimportzipfilemaxsize () +" byte limit, please assign a secondary import. ");
Ajaxutil.ajaxwrite (Jsonutils.object2json (result));
}else {
Logutils.logexception (exceededexception);
Result.setmessage ("Occurrence of unusual information");
Ajaxutil.ajaxwrite (Jsonutils.object2json (result));
}
return null;
}
}