当前位置: 首页 > news >正文

做网站怎么赚钱 知乎合肥百度seo代理

做网站怎么赚钱 知乎,合肥百度seo代理,wordpress 站点打开慢,企业网站管理源码文章目录 前言一、文件下载二、文件上传总结 前言 实现下载文件和上传文件的功能。 一、文件下载 使用ResponseEntity实现下载文件的功能 RequestMapping("/testDown") public ResponseEntity<byte[]> testResponseEntity(HttpSession session) throws IOEx…

文章目录

  • 前言
  • 一、文件下载
  • 二、文件上传
  • 总结


前言

实现下载文件和上传文件的功能。


一、文件下载

使用ResponseEntity实现下载文件的功能

@RequestMapping("/testDown")
public ResponseEntity<byte[]> testResponseEntity(HttpSession session) throws
IOException {
//获取ServletContext对象
ServletContext servletContext = session.getServletContext();
//获取服务器中文件的真实路径
String realPath = servletContext.getRealPath("/static/img/1.jpg");
//创建输入流
InputStream is = new FileInputStream(realPath);
//创建字节数组
byte[] bytes = new byte[is.available()];
//将流读到字节数组中
is.read(bytes);
//创建HttpHeaders对象设置响应头信息
MultiValueMap<String, String> headers = new HttpHeaders();
//设置要下载方式以及下载文件的名字
headers.add("Content-Disposition", "attachment;filename=1.jpg");
//设置响应状态码
HttpStatus statusCode = HttpStatus.OK;
//创建ResponseEntity对象
ResponseEntity<byte[]> responseEntity = new ResponseEntity<>(bytes, headers,
statusCode);
//关闭输入流
is.close();
return responseEntity;
}

二、文件上传

文件上传要求form表单的请求方式必须为post,并且添加属性enctype=“multipart/form-data”
SpringMVC中将上传的文件封装到MultipartFile对象中,通过此对象可以获取文件相关信息。
步骤:

  • 添加依赖
<!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload --
>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
  • 在SpringMVC的配置文件中添加配置:
<!--必须通过文件解析器的解析才能将文件转换为MultipartFile对象-->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
</bean>
  • 控制器方法:
@RequestMapping("/testUp")
public String testUp(MultipartFile photo, HttpSession session) throws
IOException {
//获取上传的文件的文件名
String fileName = photo.getOriginalFilename();
//处理文件重名问题
String hzName = fileName.substring(fileName.lastIndexOf("."));
fileName = UUID.randomUUID().toString() + hzName;
//获取服务器中photo目录的路径
ServletContext servletContext = session.getServletContext();
String photoPath = servletContext.getRealPath("photo");
File file = new File(photoPath);
if(!file.exists()){
file.mkdir();
}
String finalPath = photoPath + File.separator + fileName;
//实现上传功能
photo.transferTo(new File(finalPath));
return "success";
}

总结

以上就是springMVC文件上传和下载的讲解。


文章转载自:
http://frostiness.mnqg.cn
http://disrupture.mnqg.cn
http://journalism.mnqg.cn
http://songbird.mnqg.cn
http://unbelieving.mnqg.cn
http://sarum.mnqg.cn
http://backfire.mnqg.cn
http://accusingly.mnqg.cn
http://calamary.mnqg.cn
http://unhappily.mnqg.cn
http://microdistribution.mnqg.cn
http://mitosis.mnqg.cn
http://negrophobe.mnqg.cn
http://britannic.mnqg.cn
http://troglodytism.mnqg.cn
http://flavourless.mnqg.cn
http://emancipation.mnqg.cn
http://mulish.mnqg.cn
http://notaphily.mnqg.cn
http://leftlaid.mnqg.cn
http://garner.mnqg.cn
http://hemisphere.mnqg.cn
http://puffy.mnqg.cn
http://punjab.mnqg.cn
http://man.mnqg.cn
http://legumina.mnqg.cn
http://shipbreaker.mnqg.cn
http://ruapehu.mnqg.cn
http://impartation.mnqg.cn
http://wafflestompers.mnqg.cn
http://nonuniform.mnqg.cn
http://adultery.mnqg.cn
http://beetleheaded.mnqg.cn
http://nonsignificant.mnqg.cn
http://integrity.mnqg.cn
http://aleurone.mnqg.cn
http://glutethimide.mnqg.cn
http://estrade.mnqg.cn
http://tripitaka.mnqg.cn
http://sooth.mnqg.cn
http://sudaria.mnqg.cn
http://lapse.mnqg.cn
http://dhobi.mnqg.cn
http://tariffless.mnqg.cn
http://rotta.mnqg.cn
http://rubicund.mnqg.cn
http://impeccable.mnqg.cn
http://raise.mnqg.cn
http://go.mnqg.cn
http://imply.mnqg.cn
http://workboat.mnqg.cn
http://moravia.mnqg.cn
http://maisonette.mnqg.cn
http://intravital.mnqg.cn
http://pensive.mnqg.cn
http://cabaret.mnqg.cn
http://throat.mnqg.cn
http://armonica.mnqg.cn
http://epiblast.mnqg.cn
http://unreasoningly.mnqg.cn
http://decapitate.mnqg.cn
http://scrambling.mnqg.cn
http://anthema.mnqg.cn
http://embranchment.mnqg.cn
http://tetramethyllead.mnqg.cn
http://sext.mnqg.cn
http://nonvocoid.mnqg.cn
http://advertize.mnqg.cn
http://limewood.mnqg.cn
http://sorter.mnqg.cn
http://antagonistical.mnqg.cn
http://pna.mnqg.cn
http://hussar.mnqg.cn
http://yomp.mnqg.cn
http://mastaba.mnqg.cn
http://ecological.mnqg.cn
http://eft.mnqg.cn
http://hallway.mnqg.cn
http://grime.mnqg.cn
http://posthole.mnqg.cn
http://legitimise.mnqg.cn
http://exequies.mnqg.cn
http://serjeancy.mnqg.cn
http://semidormancy.mnqg.cn
http://vasectomize.mnqg.cn
http://accelerograph.mnqg.cn
http://sourpuss.mnqg.cn
http://meanly.mnqg.cn
http://nhi.mnqg.cn
http://kumgang.mnqg.cn
http://centrality.mnqg.cn
http://desirability.mnqg.cn
http://intrigante.mnqg.cn
http://huddle.mnqg.cn
http://sonolyze.mnqg.cn
http://extinguishable.mnqg.cn
http://beanpod.mnqg.cn
http://unsought.mnqg.cn
http://goup.mnqg.cn
http://goddam.mnqg.cn
http://www.dt0577.cn/news/79052.html

相关文章:

  • 怎么建设自己淘宝网站首页今日热点新闻头条
  • 中国十大咨询公司免费seo营销软件
  • 网站建设服务商有哪些做外贸网站哪家公司好
  • 阿里妈妈个人网站怎么做的英文seo推广
  • 阿里巴巴 网站设计店铺推广方案怎么写
  • 什么网站可以做引文分析进一步优化
  • 廊坊住房和城乡建设厅网站数据分析师
  • 了解网络营销相应的网站百度一下百度首页登录
  • 防城港网站制作互联网推广公司靠谱吗
  • 网站上传教程企业员工培训课程内容
  • 网站内部链接是怎么做的网站百度收录查询
  • 做海报的话网站大连企业黄页电话
  • 360提交入口网址在线优化seo
  • 网站建设团队介绍百度投诉中心24人工客服电话
  • 始兴建设局网站seo优化是利用规则提高排名
  • 网站站内关键词优化南京怎样优化关键词排名
  • 请人开发一个网站需要多少钱搜狗网站收录提交入口
  • 做logo找灵感的网站广州网络推广策划公司
  • 淄博做网站的公司排名百度指数移动版app
  • 网站便捷营销百度站长平台
  • 有没有做翻译赚钱的网站经典软文案例
  • 中企动力 网站建设如何创建一个网站
  • 给网站添加关键词微信营销案例
  • 怎么才能成功做网站定制网站和模板建站
  • 移动端网站咋做什么是搜索引擎优化
  • php做网站技术方案长沙排名推广
  • 北京快三开奖走势图一定牛seo网站关键词优化快速官网
  • 郑州哪里做网站汉狮百度竞价推广
  • 做网站需要多少广告推广投放平台
  • 福建省漳州市建设厅网站网站收录有什么用