文件上传
以前觉得这是个十分高大上的功能,结果发现,只要使用实用的工具类,五分钟就能搞定一个文件上传的功能了!
环境搭建
前提是已经搭建好开发环境。
- 创建JavaWEB项目
- Tomcat服务器安装
步骤
1. 下载工具类:smartupload
- 将其导入到项目的lib目录下
2. 写一个前端页面,此处是在jsp页面中写了一个form表单,命名为index.jsp
<%--
Created by IntelliJ IDEA.
User: Elvira
Date: 2020/11/16
Time: 20:47
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>主页</title>
</head>
<body>
文件上传:<br>
<form action="/upload" method="post" enctype="multipart/form-data">
名称:<input type="text" name="uname"><br>
文件:<input type="file" name="myfile"><br>
<input type="submit" value="上传">
</