Ajax Tutorialcolumn shares the specific code for Ajax file upload for your reference. The specific content is as follows
Front-end form and JQuery jsp/html code
Using JQury
Front-end form
ajax request server
Conroller.java
@PostMapping("/upload") public void fileUpload2(@RequestParam("file") CommonsMultipartFile file, HttpServletRequest request) throws IOException { System.out.println("走了"); //上传路径保存设置 String path = request.getServletContext().getRealPath("/upload"); File realPath = new File(path); if (!realPath.exists()) { realPath.mkdir(); } //上传文件地址 System.out.println("上传文件保存地址:" + realPath); //通过CommonsMultipartFile的方法直接写文件(注意这个时候) file.transferTo(new File(realPath + "/" + file.getOriginalFilename())); }
Result
The above is the entire content of this article, I hope it will be helpful to everyone's study.
Related free learning recommendations:javascript(video)
The above is the detailed content of Implement Ajax file upload function. For more information, please follow other related articles on the PHP Chinese website!