1. 代码:
class="java" name="code"> @RequestMapping({ "/fileUpload.htm" })
public String fileUpload(Model model, HttpServletRequest request,
HttpServletResponse response, @RequestParam MultipartFile upload){
String fileType = request.getParameter("fileType");
String fileName = upload.getOriginalFilename();
String realPath = request.getSession().getServletContext().getRealPath("/upload");
File newFile = new File(realPath, fileName);
try {
FileUtils.copyInputStreamToFile(upload.getInputStream(), newFile);
PrintWriter out = response.getWriter();
out.print(newFile.getPath());
out.flush();
} catch (IOException e) {
LOGGER.error("文件上传失败",e.getMessage());
}
return "orderPay/check/acceptFileList";
}
2. jsp代码:
<form id="upForm" method="post" enctype="multipart/form-data" action="${basePath}/orderPay/fileUpload.htm" >
<input type="file" name="upload" id="upload"/><br/>
<input type="hidden" id="id" name="id" />
<input type="hidden" id="instNo" name="instNo" />
[url=#]提交[/url]
[url=#]取消[/url]
</form>