File Upload in Jfinal and Jfinal File Upload
File Upload and import the corresponding package. You only need one code (the imported package is Baidu)
1 public UploadFile getFile(String parameterName, String saveDirectory, Integer maxPostSize, String encoding)2 3 public List<UploadFile> getFiles(String saveDirectory, Integer maxPostSize, String encoding)
Two Methods: pass in a single file on the first jsp page, and pass in multiple files on the second.
ParameterName corresponds to <input name = "corresponding to this name"/>
For example:
1 public class FileController extends Controller {2 public void upload () {3 try {4 // if the second parameter is a, save it to the upload/a folder, automatically create a folder 5 UploadFile file = getFile ("photo", "a", 100*1024*1024, "UTF-8"); 6 7 8} catch (Exception exception) {9 System. out. println ("path error"); 10} 11 renderJsp ("/pages/success. jsp "); 12} 13}
The file will be stored in the upload under the project added in your tomcat
Custom path:
1 public class JConfig extends JFinalConfig {2 3 @ Override4 public void configConstant (Constants me) {5 // development mode 6 me. setDevMode (true); 7 me. setViewType (ViewType. JSP); 8 me. setBaseUploadPath ("D: // upload"); 9}
Use me. setBaseUploadPath ("D: // upload"). For example, set the path to D: // upload in the code.
When you upload a file later, the path parameter you fill in will be added to this end. You do not need to fill in the file name and will automatically save it as the uploaded file name.
You can modify the file name to be uploaded at the front end (not tried)