资源简介
SpringMVC文件上传与下载的实现.rar
代码片段和文件信息
package com.mlxp.controller;
import java.io.File;
import java.io.OutputStream;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.FileUtils;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import com.mlxp.entity.User;
@Controller
@RequestMapping(“/hellorabbit/*.do“)
public class DownloadController {
@RequestMapping
public String hellomlxp(){
System.out.println(“hellomlxp“);
return “upload“;
}
@RequestMapping
public String hellouser(){
System.out.println(“hellouser“);
return “register“;
}
@RequestMapping(method=RequestMethod.POST)
public String upload(HttpServletRequest request
@RequestParam(“description“) String description
@RequestParam(“file“) MultipartFile fileModel model) throws Exception {
System.out.println(description);
// //不使用注解
// MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
// //获取file
// MultipartFile file = multipartRequest.getFile(“file“);
//如果文件不为空,写入上传路径
if(!file.isEmpty()) {
// //上传文件路径
// String path = request.getSession().getServletContext().getRealPath(“/ooxx/“);
//由配置文件获取
String path=(String) request.getSession().getServletContext().getAttribute(“path“);
//上传文件名
String filename = file.getOriginalFilename();
File filepath = new File(pathfilename);
//判断路径是否存在,如果不存在就创建一个
if (!filepath.getParentFile().exists()) {
filepath.getParentFile().mkdirs();
}
// // 读取要下载的文件,保存到文件输入流
// InputStream in = file.getInputStream();
// // 创建输出流
// BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(filepath));
// // 创建缓冲区
// byte[] buffer = new byte[32 * 10 * 1024];
// int bytesRead = 0;
// // 循环将输入流中的内容读取到缓冲区当中
// while ((bytesRead = in.read(buffer)) != -1){
// // 输出缓冲区的内容到浏览器,实现文件下载
// out.write(buffer 0 bytesRead);
// }
// // 关闭输出流
// out.close();
// // 关闭文件输入流
// in.close();
//将上传文件保存到一个目标文件当中
file.transferTo(new File(path + File.separator + filename));
model.addAttribute(“filename“ filename);
return “download
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 852 2017-09-26 13:30 Download_demo\.classpath
文件 1046 2017-09-21 13:35 Download_demo\.project
文件 517 2017-09-26 13:30 Download_demo\.settings\.jsdtscope
文件 364 2017-09-15 13:59 Download_demo\.settings\org.eclipse.jdt.core.prefs
文件 117 2017-09-21 13:36 Download_demo\.settings\org.eclipse.jst.j2ee.ejb.annotations.xdoclet.prefs
文件 463 2017-09-26 13:30 Download_demo\.settings\org.eclipse.wst.common.component
文件 345 2017-09-26 13:30 Download_demo\.settings\org.eclipse.wst.common.project.facet.core.xm
文件 49 2017-09-15 13:59 Download_demo\.settings\org.eclipse.wst.jsdt.ui.superType.container
文件 6 2017-09-15 13:59 Download_demo\.settings\org.eclipse.wst.jsdt.ui.superType.name
文件 6319 2017-09-26 13:39 Download_demo\build\classes\com\mlxp\controller\DownloadController.class
文件 909 2017-09-26 13:39 Download_demo\build\classes\com\mlxp\entity\User.class
文件 2296 2017-09-26 13:39 Download_demo\build\classes\com\mlxp\listener\PropertiesListener.class
文件 13 2017-09-26 11:16 Download_demo\build\classes\path.properties
文件 2105 2017-09-26 13:30 Download_demo\build\classes\spring-mvc.xm
文件 843 2017-09-26 13:30 Download_demo\build\classes\spring.xm
文件 6913 2017-09-26 13:39 Download_demo\src\com\mlxp\controller\DownloadController.java
文件 635 2017-09-21 15:11 Download_demo\src\com\mlxp\entity\User.java
文件 1769 2017-09-26 13:30 Download_demo\src\com\mlxp\listener\PropertiesListener.java
文件 13 2017-09-26 11:16 Download_demo\src\path.properties
文件 2105 2017-09-26 13:30 Download_demo\src\spring-mvc.xm
文件 843 2017-09-26 13:30 Download_demo\src\spring.xm
文件 86 2017-09-26 13:30 Download_demo\WebContent\index.jsp
文件 78601 2015-01-02 15:00 Download_demo\WebContent\js\jquery-1.4.4.min.js
文件 39 2017-09-15 13:59 Download_demo\WebContent\me
文件 188671 2015-01-02 15:59 Download_demo\WebContent\WEB-INF\lib\commons-beanutils-1.7.0.jar
文件 46725 2015-01-02 15:59 Download_demo\WebContent\WEB-INF\lib\commons-codec-1.3.jar
文件 571259 2015-01-02 15:59 Download_demo\WebContent\WEB-INF\lib\commons-collections-3.2.jar
文件 71442 2015-01-02 15:59 Download_demo\WebContent\WEB-INF\lib\commons-discovery-0.2.jar
文件 59590 2015-01-02 15:59 Download_demo\WebContent\WEB-INF\lib\commons-fileupload-1.2.2.jar
文件 278799 2015-01-02 15:59 Download_demo\WebContent\WEB-INF\lib\commons-httpclient-3.0-rc4.jar
............此处省略55个文件信息
相关资源
- PID_AutoTune_v0.rar
- vspd7.2.308.zip
- 价值2k的H漫画小说系统
- Pythonamp;课堂amp;笔记(高淇amp;400;集第
- ddos压力测试工具99657
- UML建模大全
- 开源1A锂电池充电板TP4056原理图+PCB
- m1卡 ic卡可选择扇区初始化加密软件
- TSCC.exe
- FTP课程设计(服务端+客户端)
- 计算机图形学 边填充算法实现代码
- 电力系统潮流计算程序集合
- oracle数据迁移项目实施方案
- Web Api 通过文件流 文件到本地
- Visio图标-最新最全的网络通信图标库
- Spire API文档
- OpenGL参考手册
- Python中Numpy库最新教程
- SPD博士V5.3.exe
- 直流无刷电机方波驱动 stm32 例程代码
- layui后台管理模板
- 仿知乎界面小程序源代码
- 云平台-阿里云详细介绍
- photoshop经典1000例
- scratch垃圾分类源码(最终版本).sb
- IAR ARM 7.8破解
- TI CCS V5.4 安装步骤及破解文件
- 松下plc FP-XH的驱动
- 局域网硬件信息收集工具
- 加快Windows XP操作系统开机速度
评论
共有 条评论