Steps:
1. Get the Avatar (file,contenttype,filename)
2. Save Avatar
2.1. Save avatar to the specified file directory
2.2. Set the user Picture path
Specific operation
In the user management of the Add, edit page, you can upload the user's avatar, the page of the Avatar field refers to the Type=file text field.
<input type= "File" name= "Headimg"/>
After that, Useraction receives the 3 basic attribute variables that the file needs to configure:
Save the Avatar file in the server's Upload/user directory, and the name of the file is renamed with the UUID. (Must rename: ① problem with duplicate name ② special character in display)
1 //working with Avatars2 if(Headimg! =NULL){3 //1. Save Avatar to Upload/user4 //gets the absolute address of the saved path5String FilePath = Servletactioncontext.getservletcontext (). Getrealpath ("Upload/user");6String fileName = Uuid.randomuuid (). toString (). ReplaceAll ("-", "") + headimgfilename.substring ( Headimgfilename.lastindexof ("."));7 //Copying Files8Fileutils.copyfile (Headimg,NewFile (FilePath, FileName));9 Ten //2. Set the user picture path OneUser.setheadimg ("user/" +fileName); A}
(eight) Avatar upload