@MultipartConfig@WebServlet("/uploads")public class Upload extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); Part part = req.getPart("file"); String realPath = getServletContext().getRealPath("fileUpload"); System.out.println(realPath); String header = part.getHeader("Content-Disposition"); String[] array = header.split(";"); String filename = array[array.length - 1]; String[] arr = filename.split("="); String filerealname = arr[arr.length - 1]; String file = filerealname.substring(1, filerealname.length() - 1); System.out.println(file); System.out.println(realPath + "\\" + file); part.write(realPath + "\\" + file); } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { doGet(req, resp); }}