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---< ; 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>