1.上传图片前端:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="Servlet01" method="post" enctype="multipart/form-data">
用户名:<input type="text" name="username"><br>
密码:<input type="password" name="password"><br>
头像:<input type="file" name="head"><br>
<button>提交</button>
</form>
</body>
</html>
---重要的是要设置enctype才能传文件,但是由于设置了enctype后,request.getParameter(“”)函数将无法获取到正确的键值对数据,全部为null;
2.Servlet01代码:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
/*String name = request.getParameter("use