First, please step http://jquery-plugins.net/image-cropper-jquery-image-cropping-plugin download iamge cropper about JS files and CSS files, Download demo learn to use;
Java provides the background, page picture placement Click the pop-up modal box, the modal box on the File box selection after the picture immediately upload the original image to the server and display on the page (show need to get an agent), the page to zoom, select, Submit x (horizontal), Y (ordinate), Fator scale to the background, Background according to these parameters to crop the picture, after the successful cropping and then tell the picture to close the pop-up modal box, modal box page called the parent page JS to assign value, that is, the image after the interception is displayed on the main page;
Provide key code:
The modal box selects the picture that needs to be shown in the servlet of the Capture box (with the Web. xml):
/**
* Title: Generic file Download servlet
* Description: Generic file Download servlet
* Copyright:copyright (c) 2015
* Company:zte
* @author DJW
* @version 1.0
*/
public class Downloadimageservlet extends HttpServlet {
Private static final long serialversionuid = 1L;
private static final String Local_charset = "UTF-8";
Public Downloadimageservlet () {
Super ();
}
public void DoPost (HttpServletRequest request, httpservletresponse response)
Throws Servletexception, IOException {
Doget (Request,response);
}
public void doget (HttpServletRequest request, httpservletresponse response)
Throws Servletexception, IOException {
Request.setcharacterencoding (Local_charset);
String filename = request.getparameter ("filename");
String FileType = Request.getparameter ("FileType");
if (filename = = null) {
Return
}
else{
filename = new String (filename.getbytes ("Iso-8859-1"), Local_charset);
}
//If the foreground does not have an incoming file path, take
String filepath = request.getparameter ("filepath") from the path of the system configuration file setting;
if (filepath = = NULL | | fi Lepath.trim (). Equals ("")) {
//filepath = common.getconfig ("Upload.uploadfiledirectory");
filepath = "c:/users/djw/desktop/";
}
else{
filepath = new String (filepath.getbytes ("Iso-8859-1"), Local_charset);
}
//Set the response header and download the saved file name
String newName = Request.getparameter ("NewName");
String resfilename = "";
if (newName = = null)
{
Resfilename = new String (Filename.getbytes (), "iso-8859-1");
}else{
Resfilename = new String (Newname.getbytes (), "iso-8859-1");
}
if ("Video". Equals (FileType)) {
Response.setcontenttype ("Video/mp4");
} else{
Response.setcontenttype ("application/octet-stream;charset=" + Local_charset);
}
Response.setheader ("content-disposition", "attachment; Filename=\ "" + resfilename + "\" ");
//Open stream information for the specified file
file F = new file (filepath,filename);
//write out flow information
/*
* Java.io.FileInputStream Filein = new Java.io.FileInputStream (f);
* Servletoutputstream OS = Response.getoutputstream (); int i_length =
* Filein.available (); byte buf_1[] = new Byte[i_length]; While
* (I_length > 0) {filein.read (buf_1); Os.write (buf_1); i_length =
* Filein.available (); } os.close (); Filein.close ();
*/
Response.setcontentlength ((int) f.length ());
int i = 0;
byte[] bt = new byte[8192];
Servletoutputstream SOS = null;
FileInputStream FIS = null;
try {
FIS = new FileInputStream (f);
SOS = Response.getoutputstream ();
while ((i = Fis.read (BT))! =-1) {
Sos.write (BT, 0, I);
}
} catch (FileNotFoundException ex) {
}
catch (Exception ex) {
}
finally {
if (SOS! = null) {
try {
Sos.flush ();
Sos.close ();
} catch (IOException ex) {
}
SOS = NULL;
}
if (FIS! = null) {
try {
Fis.close ();
} catch (IOException ex) {
}
}
}
}
The page display picture can use the project address + "Downloadimageservlet?" + Picture Name
Image Cropper+java Implementation Tool