Implement Ajax file upload function

coldplay.xixi
Release: 2020-12-07 17:53:15
forward
3309 people have browsed it

Implement Ajax file upload function

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

Copy after login

Front-end form

请选择要上传的文件:

Copy after login

ajax request server

Copy after login

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())); }
Copy after login

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!

Related labels:
source:jb51.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!