图片上传:
<form action="shop.do?p=regist" method="post" enctype="multipart/form-data">
姓名:<input type=text name=username> <br>
玉照:<input type=file name="face"> <br>
<input type=submit value="注册">
</form>
//文件上传
public void doRegist(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//文件上传(requet,存放位置,最大大小,编码)
String realPath = request.getSession().getServletContext().getRealPath("/upload");
System.out.println(realPath);
//第二个参数是文件保存的路径,第三个试试文件大小,第四个是文件保存的格式
MultipartRequest mr = new MultipartRequest(request,realPath,1024*1024,"utf-8");
// MultipartRequest mr = new MultipartRequest();
//其它字段
String username = mr.getParameter("username");
System.out.println(username);
PrintWriter pw = response.getWriter();
System.out.println(mr);
pw.print(realPath);
pw.print("成功");
}