FileUploadInterceptor: the interceptor is at the 10th position of defaultStack. You can see its name as it is used to process file uploads. For file uploads, you should know: struts2 uses the commons-fileupload component to process file uploads. When we set the enctype attribute to "multipart/form-data" in the form, this indicates that this is a file upload request, when struts2 receives such a request, it encapsulates the request in a MultiPartRequestWrapper object, while MultiPartRequestWrapper encapsulates JakartaMultiPartRequest. The JakartaMultiPartRequest object is the request object that actually processes the file upload. The following describes three important attributes of the Interceptor: 1. maximumSize --> maximum size of the file to be uploaded. The unit is byte (bytes) 2. allowedTypesSet --> allows a set of file types to be uploaded. 3. allowedExtensionsSet --> to upload a file with a file extension set, all three conditions must be met before the file can be uploaded successfully. The following describes the intercept method of the Interceptor: [java] public String intercept (ActionInvocation invocation) throws Exception {ActionContext ac = invocation. getInvocationContext (); // get the ActionContext object // get the request object HttpServletRequest request = (HttpServletRequest) ac. get (ServletActionContext. HTTP_REQUEST); // determine whether it is a file upload request if (! (Request instanceof MultiPartRequestWrapper) {if (LOG. isDebugEnabled () {ActionProxy proxy = invocation. getProxy (); LOG. debug (getTextMessage ("struts. messages. bypass. request ", new Object [] {proxy. getNamespace (), proxy. getActionName ()}, ac. getLocale ();} // call the next interceptor directly if not, because the file upload return invocation is not required. invoke ();} ValidationAware validation = null; Object action = invocation. getAction (); // get the current Acti On Object // determines whether the ValidationAware interface is implemented. When an Action inherits from the ActionSupport class, it implements the if (action instanceof ValidationAware) {validation = (ValidationAware) action ;} // As mentioned earlier, the request type for file upload is MultiPartRequestWrapper multiWrapper = (MultiPartRequestWrapper) request. // you can determine whether an error occurs during file upload, that is, whether the above three upload conditions, if (multiWrapper. hasErrors () {for (String error: multiWrapper. getErrors () {if (validation! = Null) {// if there is an error, add ActionError. Note that validation is the current Action object validation. addActionError (error);} LOG. warn (error) ;}/// obtain the parameter name of the uploaded file (name attribute value of input) for Enumeration, because struts2 supports the upload of multiple files under the Enumeration fileParameterNames = multiWrapper. getFileParameterNames (); while (fileParameterNames! = Null & fileParameterNames. hasMoreElements () {// iteration // The parameter name of the current file String inputName = (String) fileParameterNames. nextElement (); // obtain the type of the uploaded file. Because the name attribute of multiple uploaded files can be the same, the array String [] contentType = multiWrapper is used here. getContentTypes (inputName); if (isNonEmpty (contentType) {// obtain the real name of the uploaded file (name in the client file system ), as for why the returned values are arrays and strings [] fileName = multiWrapper. getFileNames (inputName); if (isNonEmpty (fileName )){// Get the uploaded File [] files = multiWrapper. getFiles (inputName); if (files! = Null & files. length> 0) {List <File> acceptedFiles = new ArrayList <File> (files. length); List <String> acceptedContentTypes = new ArrayList <String> (files. length); List <String> acceptedFileNames = new ArrayList <String> (files. length); String contentTypeName = inputName + "ContentType"; String fileNameName = inputName + "FileName "; // This is the reason why the file type received during file upload is fixed with the file name. // the array of iterative files for (int index = 0; index <fi Les. length; index ++) {// determines whether the file is legal. if it is legal, add it to the legal set if (acceptFile (action, files [index], fileName [index], contentType [index], inputName, validation, ac. getLocale () {acceptedFiles. add (files [index]); acceptedContentTypes. add (contentType [index]); acceptedFileNames. add (fileName [index]) ;}// if the valid file set is not empty if (! AcceptedFiles. isEmpty () {Map <String, Object> params = ac. getParameters (); // stores the uploaded file, file type, and file name in the parameters Map of ActionContext. put (inputName, acceptedFiles. toArray (new File [acceptedFiles. size ()]); params. put (contentTypeName, acceptedContentTypes. toArray (new String [acceptedContentTypes. size ()]); params. put (fileNameName, acceptedFileNames. toArray (new String [acceptedFileNames. size ()]) ;}}} Else {LOG. warn (getTextMessage (action, "struts. messages. invalid. file ", new Object [] {inputName}, ac. getLocale () ;}} else {LOG. warn (getTextMessage (action, "struts. messages. invalid. content. type ", new Object [] {inputName}, ac. getLocale ();} // call the next Interceptor. Of course, the Action String result = invocation is also called. invoke (); // after the Action is executed, the interceptor returns and executes the Action in sequence to clear the temporary file fileParameterNames = multiWrapper when the file is uploaded. getFileParame TerNames (); while (fileParameterNames! = Null & fileParameterNames. hasMoreElements () {String inputValue = (String) fileParameterNames. nextElement (); File [] files = multiWrapper. getFiles (inputValue); for (File currentFile: files) {if (LOG. isInfoEnabled () {LOG.info (getTextMessage (action, "struts. messages. removing. file ", new Object [] {inputValue, currentFile}, ac. getLocale ();} if (currentFile! = Null) & currentFile. isFile () {if (currentFile. delete () = false) {// currentFile is called here. delete () deletes the temporary file, because the processing of the uploaded file in Action has been completed. warn ("Resource Leaking: cocould not remove uploaded file '" + currentFile. getCanonicalPath () + "'. ") ;}}}// return the previous interceptor return result;} next, let's see how the interceptor judges whether the uploaded file is legal, that is, the acceptFile method: [java] protected boolean acceptFile (Object action, File file, String filename, String contentT Ype, String inputName, ValidationAware validation, Locale locale) {boolean fileIsAcceptable = false; // If it's null the upload failed if (file = null) {String errMsg = getTextMessage (action, "struts. messages. error. uploading ", new Object [] {inputName}, locale); if (validation! = Null) {validation. addFieldError (inputName, errMsg);} LOG. warn (errMsg);} else if (maximumSize! = Null & maximumSize <file. length () {String errMsg = getTextMessage (action, "struts. messages. error. file. too. large ", new Object [] {inputName, filename, file. getName (), "" + file. length ()}, locale); if (validation! = Null) {validation. addFieldError (inputName, errMsg);} LOG. warn (errMsg);} else if ((! AllowedTypesSet. isEmpty ())&&(! ContainsItem (allowedTypesSet, contentType) {String errMsg = getTextMessage (action, "struts. messages. error. content. type. not. allowed ", new Object [] {inputName, filename, file. getName (), contentType}, locale); if (validation! = Null) {validation. addFieldError (inputName, errMsg);} LOG. warn (errMsg);} else if ((! AllowedExtensionsSet. isEmpty ())&&(! HasAllowedExtension (allowedExtensionsSet, filename) {String errMsg = getTextMessage (action, "struts. messages. error. file. extension. not. allowed ", new Object [] {inputName, filename, file. getName (), contentType}, locale); if (validation! = Null) {validation. addFieldError (inputName, errMsg);} LOG. warn (errMsg);} else {fileIsAcceptable = true;} return fileIsAcceptable;} the logic of this method is very simple, that is, to determine whether the uploaded file is null in sequence and whether it meets the specified file size, whether the specified file type and the specified file extension are met. If the file type and file extension are not set, the file type and file extension are not limited. In defaultStack, neither of the two interceptors is set, but the maximum size of the uploaded file is set. Some people will say that maximumSize is not set either? Yes, maximumSize is not set in this Interceptor. The default value is null. As mentioned earlier, the request object that actually processes file uploads is JakartaMultiPartRequest, in JakartaMultiPartRequest there is a corresponding maxSize attribute which injects this value through the struts2 container when instantiating the JakartaMultiPartRequest object, the configuration of this value in the struts2-core.jar org. apache. default in the struts2 package. in the properties file (struts. multipart. maxSize = 2097152). The default value is 2097152, that is, 2 MB. When uploading a file, we define the corresponding attributes in the Action to receive the uploaded file, file type and file name, however, the interceptor does not call the current Action to set the file to be uploaded, that is, the corresponding setXxx (), setXxxContentType (), and setXxxFileName () methods are not called, xxx is the name attribute value of input. It only stores the uploaded file, file type, and file name in parameters Map of ActionContext. This problem is explained in the ParametersInterceptor interceptor. This interceptor is different from the previous interceptors in that it calls the next interceptor and Action after a certain logic is executed, after the Action interceptor is executed, it returns the temporary files generated after the interceptor continues to clean up the uploaded files. This is determined by the functions to be implemented by the interceptor.