public ActionForward upload(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
MuliUploadForm m = (MuliUploadForm) form;
Hashtable map = m.getMultipartRequestHandler().getFileElements();
Enumeration enums = map.keys();
if (map != null && map.size() > 0) {
while (enums.hasMoreElements()) {
String key = (String) enums.nextElement();
FormFile formFile = (FormFile) map.get(key);
String path = request.getSession().getServletContext()
.getRealPath("/upload")
+ "/" + formFile.getFileName();
uploads(formFile, path);
}
}
return null;
}
// 文件上传
private void uploads(FormFile formFile, String path) throws Exception {
InputStream is = formFile.getInputStream();
OutputStream os = new FileOutputStream(new File(path));
byte[] b = new byte[1024];
int len = 0;
while ((len = is.read(b)) != -1) {
os.write(b, 0, len);
}
os.flush();
os.close();
is.close();
System.out.println("上传成功");
}
struts1 多文件上传
最新推荐文章于 2024-12-05 13:34:56 发布