使用ApacheFileUpload组件实现文件上传
1.在pom.xml中添加所需commons-fileupload依赖
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
2.编写JSP文件,需要注意的几个点:表单项添加enctype="multipart/form-data"
,把请求方式设置为post,添加文件域<input type="file" name="imgFile">
,详情如下:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>文件上传</title>
</head>
<body>
<form action="/fileUpload" method="post" enctype="multipart/form-data">
用户名:<input type="text" name="username" id="username"><br>