没有合适的资源?快使用搜索试试~ 我知道了~
MultipartHttpServletRequest_文件上传
4星 · 超过85%的资源 需积分: 47 93 下载量 26 浏览量
2013-08-21
11:44:12
上传
评论 1
收藏 6KB TXT 举报
温馨提示
试读
6页
MultipartHttpServletRequest_文件上传
资源推荐
资源详情
资源评论
//单个文件上传
@RequestMapping(value = "/uploadFile/{path}", method = RequestMethod.POST)
@ResponseBody
public ReturnObj upload(@PathVariable("path") String _path, HttpServletRequest request,
HttpServletResponse response) {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
CommonsMultipartFile file = (CommonsMultipartFile) multipartRequest.getFile("file");
// String name = multipartRequest.getParameter("name");
String realFileName = file.getOriginalFilename();
System.out.println("文件名:" + realFileName);
String ctxPath = "";
if (StringUtils.isNotBlank(_path)) {
ctxPath = request.getSession().getServletContext().getRealPath("/") + _path + "/";
} else {
ctxPath = request.getSession().getServletContext().getRealPath("/") + "upload/";
}
System.out.println("上传路径:" + ctxPath);
File dirPath = new File(ctxPath);
if (!dirPath.exists()) {
dirPath.mkdir();
}
File uploadFile = new File(ctxPath + realFileName);
try {
FileCopyUtils.copy(file.getBytes(), uploadFile);
} catch (IOException e) {
e.printStackTrace();
return new ReturnObj(ReturnObj.ERROR);
}
@RequestMapping(value = "/uploadFile/{path}", method = RequestMethod.POST)
@ResponseBody
public ReturnObj upload(@PathVariable("path") String _path, HttpServletRequest request,
HttpServletResponse response) {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
CommonsMultipartFile file = (CommonsMultipartFile) multipartRequest.getFile("file");
// String name = multipartRequest.getParameter("name");
String realFileName = file.getOriginalFilename();
System.out.println("文件名:" + realFileName);
String ctxPath = "";
if (StringUtils.isNotBlank(_path)) {
ctxPath = request.getSession().getServletContext().getRealPath("/") + _path + "/";
} else {
ctxPath = request.getSession().getServletContext().getRealPath("/") + "upload/";
}
System.out.println("上传路径:" + ctxPath);
File dirPath = new File(ctxPath);
if (!dirPath.exists()) {
dirPath.mkdir();
}
File uploadFile = new File(ctxPath + realFileName);
try {
FileCopyUtils.copy(file.getBytes(), uploadFile);
} catch (IOException e) {
e.printStackTrace();
return new ReturnObj(ReturnObj.ERROR);
}
return new ReturnObj(ReturnObj.SUCCESS);
}
// 项目文件上传,多文件
@RequestMapping(value = "/uploadProFile", method = RequestMethod.POST)
public String uploadMore(HttpServletRequest request, HttpServletResponse response, Model model) {
String msg = "";
int _status = 0;
boolean hasFail = false;
StringBuffer sb = new StringBuffer();
String uploadType = request.getParameter("uploadType");
String proPath = "";
if (StringUtils.isNotBlank(request.getParameter("proPath"))) {
proPath = request.getParameter("proPath") + "/";
String warPath = proPath;
String jsPath = proPath
+ (request.getParameter("jsPath") == null ? "" : request.getParameter("jsPath"));
String ftlPath = proPath
+ (request.getParameter("ftlPath") == null ? "" : request
.getParameter("ftlPath"));
String imgPath = proPath
+ (request.getParameter("imgPath") == null ? "" : request
.getParameter("imgPath"));
String version = request.getParameter("versionNum");
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
System.out.println("WAR上传路径:" + warPath);
System.out.println("JS上传路径:" + jsPath);
}
// 项目文件上传,多文件
@RequestMapping(value = "/uploadProFile", method = RequestMethod.POST)
public String uploadMore(HttpServletRequest request, HttpServletResponse response, Model model) {
String msg = "";
int _status = 0;
boolean hasFail = false;
StringBuffer sb = new StringBuffer();
String uploadType = request.getParameter("uploadType");
String proPath = "";
if (StringUtils.isNotBlank(request.getParameter("proPath"))) {
proPath = request.getParameter("proPath") + "/";
String warPath = proPath;
String jsPath = proPath
+ (request.getParameter("jsPath") == null ? "" : request.getParameter("jsPath"));
String ftlPath = proPath
+ (request.getParameter("ftlPath") == null ? "" : request
.getParameter("ftlPath"));
String imgPath = proPath
+ (request.getParameter("imgPath") == null ? "" : request
.getParameter("imgPath"));
String version = request.getParameter("versionNum");
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
System.out.println("WAR上传路径:" + warPath);
System.out.println("JS上传路径:" + jsPath);
剩余5页未读,继续阅读
资源评论
- mengkang19862015-07-26竟然是txt的,还以为是整个项目代码
- liliuliu12345612014-06-30这个百度文库上也有的。。我没用到。。
- guoqiang1395552016-09-28还行,但是需要自己修改下
zhenzhen
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功