Crop and upload images using the Jcrop plugin (Spring MVC)

Source: Internet
Author: User
Tags aop base64 json min wrapper xmlns

Jcrop use See: http://code.ciaoca.com/jquery/jcrop/ page Code

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" UTF-8 "%> <!
DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >  
 Background Controller   
 @Controller public class Uploadcontroller {@PostMapping ("upload") @ResponseBody pub Lic string upload (HttpServletRequest request,string img) {string serverpath = Request.getsession (). Getservletcont  
        Ext (). Getrealpath ("/");  
        Base64 base64 = new Base64 (); try {//The actual picture data is from Data:image/jpeg;base64, after the start of byte[] k = Base64.decode (img.substring ("Data:im  
            Age/jpeg;base64, ". Length ()));  
            InputStream is = new Bytearrayinputstream (k);  
            String fileName = Uuid.randomuuid (). toString ();  

            String Imgfilepath = Serverpath + "\\usertemp\\" + fileName + ". jpg";   
            BufferedImage image = Imageio.read (IS);  
            Imageio.write (image, "JPG", new File (Imgfilepath));  
        return fileName;
            } catch (Exception e) {e.printstacktrace ();  
        return "error"; }  
    }
}
Spring MVC configuration file
<?xml version= "1.0" encoding= "UTF-8"?> <beans xmlns= "Http://www.springframework.org/schema/beans" Xmlns:co
       ntext= "Http://www.springframework.org/schema/context" xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"
       Xmlns:mvc= "Http://www.springframework.org/schema/mvc" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans.xsd Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/ Spring-context.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/ Spring-aop.xsd Http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/
             Spring-mvc.xsd "> <mvc:annotation-driven> <mvc:message-converters register-defaults=" false "> <bean class= "Org.springframework.http.converter.jsOn.  
                    Mappingjackson2httpmessageconverter "> <property name=" Supportedmediatypes "> <list> <value>text/html;charset=UTF-8</value> <val   
            Ue>application/json;charset=utf-8</value> </list> </property> </bean> </mvc:message-converters> </mvc:annotation-driven> <!--scanner Controller Components--<context:component-scan base-package= "Controller"/> <!--static Resources--<mvc:re Sources location= "/static/" mapping= "/static/**"/> <!--configuration root view--<mvc:view-controller path= "/" view- Name= "index"/> <mvc:view-controller path= "/index2" view-name= "Index2"/> <!--default View resolver---&lt ; Bean id= "Defaultviewresolver" class= "Org.springframework.web.servlet.view.InternalResourceViewResolver" > < Property Name= "ViewclaSS "value=" Org.springframework.web.servlet.view.JstlView "/> <property name=" ContentType "value=" text/html "/&
        Gt <property name= "prefix" value= "/web-inf/pages/"/> <property name= "suffix" value= ". jsp"/> </bean > </beans>

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.