两个springMVC的controller之间传递zip文件(非常感谢张晨同学提供的资料)
来源:互联网 发布:大圣娶亲知乎 编辑:程序博客网 时间:2024/04/28 22:33
class="kaobei-center-center">
<span>比对库名称</span>
<input type="text" name="name" id="name" value="${name }"/>
<br />
<span>比对库编号</span>
<input type="text" name="id" id="id" value="${num }"/>
<br />
<span>比对库描述</span>
<br />
<textarea name="description" id="description" value="${description }"></textarea>
<br />
<input type="file" id="singlefile" name="singlefile" accept="application/x-zip-compressed" value=""/>
</form>
@RequestMapping(value = "cbjccbksend.do", method = { RequestMethod.POST,RequestMethod.GET })
public String cbjccbksend(HttpServletRequest request) {
String id=request.getParameter("id");
String name=request.getParameter("name");
String description=request.getParameter("description");
String singlefile=request.getParameter("singlefile");
String path_locals = request.getSession().getServletContext()
.getRealPath("");
String path = path_locals + "/pages/cbkupload/";
File file=new File(path+singlefile);
PostMethod postMethod = new PostMethod(yunlongurl);
try {
System.out.println("我来了!++++");
Part[] parts = { new FilePart("file", file),
new StringPart("fileName", "file"),
new StringPart("id", id),
new StringPart("name", name, "UTF-8"),
new StringPart("singlefile", name, "UTF-8"),
new StringPart("description", description, "UTF-8")};
MultipartRequestEntity mre = new MultipartRequestEntity(parts,
postMethod.getParams());
postMethod.setRequestEntity(mre);
HttpClient client = new HttpClient();
client.getHttpConnectionManager().getParams().setConnectionTimeout(
50000);
// 请求
System.out.println("我走了!++++");
int status = client.executeMethod(postMethod);
// 结束时间
if (status == HttpStatus.SC_OK) {
byte[] responseBody = postMethod.getResponseBody();
String responseStr = new String(responseBody, "utf-8");
// ********业务处理
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
postMethod.releaseConnection();
}
return null;
}
@RequestMapping(value = "/acceptFile.do", method = { RequestMethod.POST,
RequestMethod.GET })
public String missionreceive(
@RequestParam(value = "file", required = false) MultipartFile file,
HttpServletRequest request) {
String name3=(String) request.getAttribute("singlefile");
String name2=file.getName();
String name1=file.getOriginalFilename();
System.out.println(name2+"==="+name1+"=="+name3);
String path_locals = request.getSession().getServletContext()
.getRealPath("");
String name=request.getParameter("singlefile");
String path = path_locals + "/pages/cbkupload/" + "111" + "/"+file.getName();
File f=new File(path);
if(!f.exists()){
f.mkdirs();
}
if (file == null) {
return "没收接收到文件";
}
System.out.println(file);
try {
OutputStream out = new FileOutputStream(f);
// 保存图片 FileCopyUtils是Spring自带的工具类
FileCopyUtils.copy(file.getInputStream(), out);
} catch (Exception e) {
e.printStackTrace();
return "报错咯";
}
return "上传成功";
}
参考资料:
http://www.zhangc.cn/post/78.html
- 两个springMVC的controller之间传递zip文件(非常感谢张晨同学提供的资料)
- SpringMvc中两个Controller类之间传递参数的方法
- 感谢我亲爱的同学
- SpringMVC——Controller和视图之间数据的相互传递
- springmvc中controller之间的跳转
- 非常感谢大家的关注!
- 谁有MCP或MCSE的试题库提供一点,非常感谢!
- 两个服务器之间文件传递(JAVA)
- SpringMVC-------->Controller获得上传文件的绝对路径
- SpringMVC-------->Controller获得上传文件的绝对路径
- 单元测试SpringMVC带文件上传的controller
- springMVC controller间跳转 重定向 传递参数的方法
- SpringMVC Controller方法将的redirect 传递参数【解决】
- SpringMVC Controller 接收页面传递的中文参数出现乱码
- springMVC controller间跳转 重定向 传递参数的方法
- SpringMVC Controller 接收页面传递的中文参数出现乱码
- 从jsp传递一个list到springmvc的Controller
- SpringMVC,Controller如何接收前端传递过来的数组
- CentOS6.5下二进制多实例安装mysql-5.6.27
- 咒真的有种种不可思议的力量吗?
- 贪心之活动选择问题
- Turtlebot(Kuboki)+Kinect+Huyoko建立gmapping地图,实现自主避障导航
- mysql创建数据库后出现Access denied for user 'root'@'%' to database ‘xxxx’
- 两个springMVC的controller之间传递zip文件(非常感谢张晨同学提供的资料)
- bzoj2527(整体二分)
- React.js: web开发者的14个工具和资源
- 音频与视频合成技术
- 单片机串口通信
- python变量命名、赋值、增量赋值操作实例
- android 如何判断开机完成
- 【Eclipse for IAR】使用 Eclipse 编写 IAR 程序
- ggplot2使用范例