Nov 19, 2010 Struts2.2.1 file upload Interceptor example. Struts2.2.1 file upload Interceptor example. In this example, we will disscuss about the file Upload Interceptor. Here, we are using a struts2.2.1 file tag for uploading a file. Struts2.2.1 utilizes the services of File Upload.
![](/uploads/1/2/7/2/127243205/318275242.jpg)
![Excel File Using Struts2 Excel File Using Struts2](/uploads/1/2/7/2/127243205/667219889.jpg)
![Using Using](/uploads/1/2/7/2/127243205/745860297.png)
.The fileUpload interceptor automatically works for all the requests that includes files.We can use this interceptor to control the working of file upload in struts2 such as defining allowed types, maximum file size etc. Parameters of fileupload interceptorThere are 2 parameters defined for fileupload interceptor. ParameterDescriptionmaximumSizespecifies maximum size of the file to be uploaded.allowedTypesspecifies allowed types. It may be image/png, image/jpg etc.Automatically added parametersIt automatically adds 2 parameters in the request:. String fileName represents the filename of the file. String contentType specifies the content type of the file.The fileName and contentType name depends on the request parameter for the file.
If filename is file, you need to use fileFileName and fileContentType. If filename is userImage, you need to use userImageFileName and userImageContentType in the Action class. Image upload example using struts 2Let's see the directory structure of file upload application. 1) Create UserImage.jspThis jsp page creates a form using struts UI tags. It receives file from the user.