Jsp page
- method should be “post”
- configure enctype=”multipart/form-data”12345<FORM id=form1 name=form1action="${pageContext.request.contextPath }/linkman_addLinkMan.action"method="post" enctype="multipart-form/data"><input type="file" name="upload">
Action file
define encapsulated variables and their get()&set()
1234567891011121314151617181920// this "upload" should be the same as the "upload" in the jsp fileprivate File upload;// file name should be (file object variable + "FileName")private String uploadFileName;public File getUpload() {return upload;}public void setUpload(File upload) {this.upload = upload;}public String getUploadFileName() {return uploadFileName;}public void setUploadFileName(String uploadFileName) {this.uploadFileName = uploadFileName;}- do upload1234567// judge if user wants to upload fileif (upload != null) {// create a file in server, "/" equals to "\\"File serverFile = new File("C:\\Users\\Peter\\Desktop\\test" + "/" + uploadFileName);// uploadingFileUtils.copyFile(upload, serverFile);}