Uploading images to a database

Source: Internet
Author: User

1 /**2 * Process of submitting Company Information3      * @paramRequest4      * @paramResponse5      * @return6      * @throwsIOException7      */8@RequestMapping (value = "/companyinfo", method =requestmethod.post)9      PublicModelandview CompanyInfo (httpservletrequest request,TenHttpServletResponse response)throwsIOException { One  AModelandview mv =NewModelandview (); -Sysusermodel Sysusermodel =Context.getcurrentuser (); -         FinalString memorysize = Config.get ("Memorysize");//Memory buffer Size the         FinalString Sizemax = Config.get ("Sizemax");//Maximum allowable value of the file -  -         FinalPrintWriter out =Response.getwriter (); -         if(servletfileupload.ismultipartcontent (Request)) { +             Try { -                 //Create a disk factory +Diskfileitemfactory factory =Newdiskfileitemfactory (); A                 //set the memory buffer size at Factory.setsizethreshold (Integer.parseint (memorysize)); -                 //Set TEMP directory -String TempDir =Request.getservletcontext (). Getrealpath ( -"/tempdir"); -File File =NewFile (tempdir); -                 if(!file.exists ()) { in File.mkdir (); -                 } to factory.setrepository (file); +                 //Creating a processing tool -Servletfileupload upload =Newservletfileupload (factory); the                 //set the maximum allowable size *                 intSetfilesize =Integer.parseint (Sizemax); $                 intFileSize =request.getcontentlength ();Panax Notoginseng Upload.setsizemax (setfilesize); -  the                 if(FileSize <=setfilesize) { +                     //parsing AString ContentType =Request.getcontenttype (); the                     if(ContentType = =NULL&& "". Equals (ContentType)) { +Mv.addobject ("msg", "File upload failed");  -                     } $                      $Class<?> clazz = Syscompanymodel.class; -Syscompanymodel Syscompanymodel =(Syscompanymodel) clazz.newinstance (); -                     if(Sysusermodel.getcompanyid ()! =NULL){ theSyscompanymodel =Syscompanyservice.getsyscompanymodelbyid (Sysusermodel.getcompanyid ()); -                     }Wuyi                      theMultiparthttpservletrequest multipartrequest =(multiparthttpservletrequest) request; -map<string, multipartfile> map =Multipartrequest.getfilemap (); WuEnumeration params =multipartrequest.getparameternames (); -                      while(Params.hasmoreelements ()) { AboutString name =(String) params.nextelement (); $String value =Multipartrequest.getparameter (name); - Beanutils.setproperty (syscompanymodel,name,value); -                     } -                          Aiterator<string> files =multipartrequest.getfilenames (); +                      the                      while(Files.hasnext ()) { -String name =Files.next (); $Multipartfile Multipartfile =multipartrequest.getfile (name); the                          the                         if(Multipartfile.getsize ()!=0){ the                             byte[] data =multipartfile.getbytes (); the                             if(Data! =NULL) { - Beanutils.setproperty (syscompanymodel,name, data); in                             } the                         } the                     } About                      theSyscompanymodel =Syscompanyservice.save (Syscompanymodel); the Sysusermodel.setcompanyid (Syscompanymodel.getcompanyid ()); theSysusermodel =Sysuserservice.save (Sysusermodel); +                      -                     //request.getsession (). SetAttribute ("UserInfo", Sysusermodel); the                     //context.setrequest (request);Bayi Mv.setviewname (Mvutils the. Redirect ("/member/companyinfo.shtml")); the}Else{ -Mv.addobject ("msg", "Upload file too large"); -                 } the}Catch(Exception e) { theMv.addobject ("msg", "File upload failed"); the             } the         } -         returnMV; the}

Uploading images to a database

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.