upload.jsp
<html:form action="/upLoad" method="post"enctype="multipart/form-data">
fileName : <html:text property="fileName" />
<br />
fileContent : <html:file property="fileContent" />
<br />
<html:submit />
</html:form>
UpLoadAction.java
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
UpLoadForm upLoadForm = (UpLoadForm) form;// TODO Auto-generated
// method stub
FormFile ff = upLoadForm.getFileContent();
String filename=ff.getFileName();
System.out.println(ff.getFileName() + ff.getContentType());
System.out.println(getServlet().getServletContext().getRealPath("/"));
try {
OutputStream outputStream = new FileOutputStream(new File("c://" + ff.getFileName()));
byte b[]=ff.getFileData();
outputStream.write(b);
outputStream.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
分享到:
相关推荐
script src =" UploadForm.js " > </ script > #用法 ###例子 var uploadForm = new UploadForm ( 'form' , 'https://cross-domain.com/upload' , { type : 'json' , // 'text', 'json', 'xm
<form id="uploadform" name="uploadform" action="/upload/do_upload" enctype="multipart/form-data" method="POST" onsubmit="return false;"> <!-- left upload --> <colgroup><col...
UploadForm uploadForm = (UploadForm) form; File file = uploadForm.getUploadedFile(); String fileName = uploadForm.getFileName(); // 保存文件到服务器 saveFile(file, fileName); return mapping....
UploadForm uploadForm = (UploadForm) form; File uploadedFile = uploadForm.getFile(); String fileName = uploadForm.getFileName(); // 验证文件大小和类型 // ... // 保存文件到服务器 File ...
UploadForm uploadForm = (UploadForm) form; DiskFileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); try { List<FileItem> items = ...
UploadForm uploadForm = (UploadForm) form; DiskFileItemFactory factory = new DiskFileItemFactory(); // 设置临时目录 factory.setRepository(new File(System.getProperty("java.io.tmpdir"))); ...
UploadForm uploadForm = (UploadForm) form; FormFile file1 = uploadForm.getTheFile(); FormFile file2 = uploadForm.getTheFile2(); // 文件保存逻辑 String savePath = "/path/to/save/files"; saveFile...
UploadForm uploadForm = (UploadForm) form; File file = uploadForm.getFile(); String fileName = uploadForm.getFileName(); // 进行文件处理... } ``` 2. **文件处理**:你可以选择将文件保存到服务器...
UploadForm uploadForm = (UploadForm) form; FormFile file = uploadForm.getFile(); // 获取文件名、类型、大小等信息 String fileName = file.getFileName(); String contentType = file.getContentType();...
UploadForm uploadForm = (UploadForm) form; FormFile file = uploadForm.getFile(); // 获取文件名、文件大小等信息 String fileName = file.getFileName(); int fileSize = file.getFileSize(); // ...
UploadForm uploadForm = (UploadForm) form; File file = uploadForm.getUploadFile(); String fileName = uploadForm.getUploadFileFileName(); // 验证文件大小、类型等 // ... // 保存文件到服务器 ...
UploadForm uploadForm = (UploadForm) form; File uploadedFile = uploadForm.getFile(); String fileName = uploadForm.getFileName(); // 实现文件保存的逻辑,例如: saveFile(uploadedFile, fileName); ...
UploadForm uploadForm = (UploadForm) form; File uploadedFile = uploadForm.getFile(); String fileName = uploadForm.getFileName(); // 检查文件大小,类型等 // ... // 保存文件到服务器 File ...
UploadForm uploadForm = (UploadForm) form; File uploadedFile = uploadForm.getFile(); String fileName = uploadForm.getFileName(); // 文件保存逻辑,如移动到服务器指定目录 File targetFile = new ...
UploadForm uploadForm = (UploadForm) form; FormFile file = uploadForm.getFile(); // 验证和保存文件 // ... return mapping.findForward("success"); } } ``` 5. **文件保存**:使用Apache Commons ...
UploadForm uploadForm = (UploadForm) form; FormFile[] files = uploadForm.getFiles(); for (FormFile file : files) { // 处理每个文件,如保存到服务器、检查文件类型等 } // 返回成功或错误的页面 } ...
UploadForm uploadForm = (UploadForm) form; FormFile file = uploadForm.getFile(); // 获取文件名、大小等信息 String fileName = file.getFileName(); int fileSize = file.getFileSize(); // 将文件...
UpLoadForm uploadForm = (UpLoadForm) form; FormFile file = uploadForm.getTheFile(); FormFile file2 = uploadForm.getTheFile2(); // 进行文件保存等逻辑处理 // ... // 返回结果页面 return mapping...
UploadForm uploadForm = (UploadForm) form; for (FormFile file : uploadForm.getFiles()) { // 获取文件名、类型等信息 String fileName = file.getFileName(); String contentType = file.getContentType()...