使用包(pom.xml)
<!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
前端upanddown.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h2>upload</h2>
<form action="/upload2" enctype="multipart/form-data"
method="post">
用户名:<input type="text" name="username"><br/>
上传文件:<input type="file" name="file1"><br/>
<input type="submit" value="提交">
</form>
<h2>download</h2>
<div>图片1</div>
<a name="photo" href="/DownloadServlet?target=1.png">png下载</a>
</body