protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
//获取文件部件part
Part part = request.getPart("file");
String h = part.getHeader("content-disposition");
String filename = h.substring(h.lastIndexOf("=") + 2, h.length() - 1);
//获取文件服务器头部信息
String root = request.getServletContext().getRealPath("/upload");
File f=new File(root);
f.mkdir();
part.write(root+"/"+filename);
}
serlvet中post方法
注意 jsp页面中file选择 的要有属性 name=‘file‘
servlet3.0文件上传功能,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/Wen-yu-jing/p/3858425.html