@WebServlet(name = "uploadServlet2", urlPatterns = "/upload2")
public class UploadServlet2 extends HttpServlet {
@Override
protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
Part part = req.getPart("file1");
//写到相对于 MultipartConfig中的location位置
part.write("a.txt");
//不保证多次调用成功,使用jetty测试时发现当调用多次,最后一次有效,即上传的文件会重命名为最后一次的文件名
part.write("b.txt");
//调用完InputStream记得关闭,否则删除不掉
InputStream is = part.getInputStream();
is.close(); //不能 part.getInputStream().close();//相当于多次获取
//删除相关的文件
part.delete();
}