分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 软件开发

文件的上传和下载

发布时间:2023-09-06 01:50责任编辑:董明明关键词:暂无标签

SpringMVC实现单文件上传

@RequestMapping("/uploadFile") ???public String upload(@RequestParam(value="file") MultipartFile file, ???????????HttpServletRequest request) throws IllegalStateException, IOException{ ???????//如果文件不为空,写入上传路径 ???????if(!file.isEmpty()) { ???????????//上传文件绝对路径 ???????????String path = request.getServletContext().getRealPath("/images/"); ???????????//上传文件名 ???????????String filename = file.getOriginalFilename(); ???????????File filepath = new File(path,filename); ???????????//判断路径是否存在,如果不存在就创建一个 ???????????if (!filepath.getParentFile().exists()) { ????????????????filepath.getParentFile().mkdirs(); ???????????} ???????????//将上传文件保存到一个目标文件当中 ???????????file.transferTo(new File(path + File.separator + filename)); ???????????String showPath = request.getContextPath()+"/images/"+filename; ???????????????????????request.setAttribute("showPath", showPath); ???????????return "hello"; ???????} else { ???????????return "error"; ???????} ???????????????????????????????????????????}

SpringMVC单文件下载

文件的上传和下载

原文地址:https://www.cnblogs.com/strugglecola/p/8918756.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved