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