SpringMVC实现文件上传下载的全过程

网友投稿 249 2022-11-10

SpringMVC实现文件上传下载的全过程

目录前言一、通用配置二、实现文件下载,上传功能总结

前言

文件的上传和下载都是基于io复制,只不过

文件上传是浏览器向服务器发送报文

文件下载是服务器向浏览器发送报文

提示:以下是本篇文章正文内容,下面案例可供参考

一、通用配置

pom.xml

org.springframework

spring-webmvc

5.3.13

ch.qos.logback

logback-classic

1.2.3

javax.servlet

javax.servlet-api

4.0.1

provided

org.thymeleaf

thymeleaf-spring5

3.0.12.RELEASE

commons-fileupload

commons-fileupload

1.3.1

org.springframework

spring-context

5.3.11

junit

junit

4.12

test

org.springframework

spring-test

5.3.13

mysql

mysql-connector-java

8.0.24

com.alibaba

druid

1.2.8

org.springframework

spring-context

5.3.11

javax.servlet

javax.servlet-api

4.0.1

provided

javax.servlet.jsp

javax.servlet.jsp-api

2.3.3

com.fasterxml.jackson.core

jackson-databind

2.12.1

commons-fileupload

commons-fileupload

1.3.1

上传功能的关键jar

web.xml

xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"

version="4.0">

字符集过滤器

characterEncodingFilter

org.springframework.web.filter.CharacterEncodingFilter

字符集编码

encoding

UTF-8

forceEncoding

true

characterEncodingFilter

/*

HiddenHttpMethodFilter

org.springframework.web.filter.HiddenHttpMethodFilter

HiddenHttpMethodFilter

/*

DispatcherServlet

org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

classpath:springMVC.xml

1

DispatcherServlet

/

xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"

version="4.0">

字符集过滤器

characterEncodingFilter

org.springframework.web.filter.CharacterEncodingFilter

字符集编码

encoding

UTF-8

forceEncoding

true

characterEncodingFilter

/*

HiddenHttpMethodFilter

org.springframework.web.filter.HiddenHttpMethodFilter

HiddenHttpMethodFilter

/*

DispatcherServlet

org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

classpath:springMVC.xml

1

DispatcherServlet

/

springMVC.xml

xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xmlns:context="http://springframework.org/schema/context"

xmlns:mvc="http://springframework.org/schema/mvc"

xsi:schemaLocation="http://springframework.org/schema/beans http://springframework.org/schema/beans/spring-beans.xsd http://springframework.org/schema/context https://springframework.org/schema/context/spring-context.xsd http://springframework.org/schema/mvc https://springframework.org/schema/mvc/spring-mvc.xsd">

text/html

application/json

xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xmlns:context="http://springframework.org/schema/context"

xmlns:mvc="http://springframework.org/schema/mvc"

xsi:schemaLocation="http://springframework.org/schema/beans http://springframework.org/schema/beans/spring-beans.xsd http://springframework.org/schema/context https://springframework.org/schema/context/spring-context.xsd http://springframework.org/schema/mvc https://springframework.org/schema/mvc/spring-mvc.xsd">

text/html

application/json

实现页面跳转,vue文件解析,上传内容解析的关键

file.html内容demo

下载1.jpg

头像:

二、实现文件下载,上传功能

下载功能测试

上传功能测试

总结

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Knative 实战:基于 Kafka 实现消息推送
下一篇:两个跟中文相关的资源工具介绍
相关文章

 发表评论

暂时没有评论,来抢沙发吧~