一.文件上传下载的实现
1.maven依赖
该功能需要添加三个jar,分别如下:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<!--是处理IO的工具类包,对java.io进行扩展,提供了更加方便的IO操作。-->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
2.前端代码
<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<html>
<head>
<title>file</title>
</head>
<body>
<form action="/fileUpload" method="post" enctype="multipart/form-data">
<a class="upload"><input class="file" type="file" name="file"></a>
<input type="submit" value="上传">
</form>
${message}
<a href="/FileDownload?fileName=${fileName}" rel="nofollow">${fileName}</a>
<%--https://www.baidu.com/s?wd=nofollow%E6%A0%87%E7%AD%BE&tn=SE_PcZhidaonwhc_ngpagmjz&rsv_dl=gh_pc_zhidao--%>
<%--nofollow不要追踪此特定链接--%>
action的内容为后端接收的地址,即为后端代码中@