本文介绍的是通过html的form标签实现文件上传功能,是一个比较简易的文件上传实例,分享一下学习成果。
客户端部分
要上传文件必须将表单enctype设置为multipart/form-data,这个参数表示表单将会以多部件表单的形式上传
enctype的默认值是enctype=”application/x-www-form-urlencoded”。这个值的意思指将会对表单项的内容进行url编码,所谓url编码就将请求参数转换为二进制编码。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form action="http://localhost:8080/upload" method="POST" enctype="multipart/form-data">
用户名:<input type="text" name="user"><br>
密码:<input type="password" name="pass"><br>
<input type="file" name="f1"><br>
<input type="submit" value="提交">
</form>
</body>
<