Springmvc with file upload call Ajax cannot connect to the background

Source: Internet
Author: User


Springmvc in the use of Ajax in the background to find the corresponding requestmapping (""), unable to enter the background, after many tests are determined to be
Multipartfile object and Ajax conflict, and do not report any exception, directly call the Ajax failure attribute method processing;
The code is as follows:
• 1@RequestMapping ("/addimage")2      PublicString AddImage (@RequestParam ("image") Multipartfile file,httpservletrequest request) {3         4Personmsgservice.setentityclass (personalmsg.class);5Personalmsg bean= (personalmsg) Personmsgservice.get (getInt (Request, "Personmsgid")));6         7String fileName =getint (Request, "Personmsgid") + ". JPG ";8 System.out.println (fileName);9         TenString path = Request.getsession (). Getservletcontext (). Getrealpath ("Upload"); One System.out.println (path); AFile targetfile =NewFile (path,filename); -         if(!targetfile.exists ()) { - targetfile.mkdirs (); the         } -         Try { - File.transferto (targetfile); -Bean.setimage (path+ "\ \" +fileName); + System.out.println (bean); - personmsgservice.saveorupdate (bean); +}Catch(IllegalStateException e) { A e.printstacktrace (); at}Catch(IOException e) { - e.printstacktrace (); -         } -         return"Redirect:/test/personmsg/tolist.spring"; -}


@RequestParam ("image") multipartfile file This parameter causes the key press Ajax to fail to match the corresponding @RequestMapping ("/addimage");
Use
Multipartrequest mrq= (multipartrequest) request; The request conversion is not successful

My workaround now is to discard the use of Ajax to submit directly using form forms;

Springmvc with file upload call Ajax cannot connect to the background

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.