This article is only dedicated to the implementation of Baidu Rich text editor, want to set the relative path and save to the database, easy to later project migration.
The version used is 1.2.3, which is suitable for cross-click on images and drag-and-drop functions.
Save the settings for the relative address of the picture
1. Modify the Uploader.java Getphysicalpath () method to set the return address
2. Please modify the relative address in imageup.jsp result
3. Modify Getallpic () in image.js to set SRC, _src return value
1, modify the background code Uploader.java
/*** Get physical path based on incoming virtual path * *@paramPath *@return */ Privatestring Getphysicalpath (string path) {//Original: Upload the file in the request path (Baidu Editor) on the first level//String Servletpath = This.request.getServletPath ();//String Realpath = this.request.getSession (). GE Tservletcontext ()//. Getrealpath (Servletpath);//return new File (Realpath). GetParent () + "/" +path; //modified version: Upload files under WebAppString ServletContext = This. Request.getsession (). Getservletcontext (). Getrealpath (""); return NewFile (ServletContext). GetParent () + "/" +path; }
2, modify the imageup.jsp
// String result = "{\" name\ ": \" "+ up.getfilename () +" \ ", \" originalname\ ": \" "+ up.getoriginalname () +" \ ", \" size\ ":" + Up.getsize () + ", \" state\ ": \" "+ up.getstate () +" \ ", \" type\ ": \" "+ up.gettype () +" \ ", \" url\ ": \" "+ up.geturl () +" \ "}"; /c2> // modified version: According to imageup.jsp relative position to modify, here the picture is placed under the WebApp (different position self-modification) String result = "{\" name\ ": \" " + up.getfilename () + "\", \ "originalname\": \ "" + up.getoriginalname () + "\", \ "size\": "+ up.getsize () +", \ "state\": \ "" + U P.getstate () + "\", \ "type\": \ "" + up.gettype () + "\", \ "url\": \ "" + Pathpre + up.geturl () + "\"} ";
3, modify the image.js
Getallpic:function(SEL, $w, editor) {varme = This, arr=[], $imgs=$ (SEL, $w); $.each ($imgs,function(Index, node) {$ (node). Removeattr ("width"). Removeattr ("height"));//if (Node.width > Editor.options.initialFrameWidth) {//Me.scale (node, editor.options.initialFrameWidth-//parseint ($ (editor.body). CSS ("Padding-left"))-//parseint ($ (editor.body). CSS ("Padding-right")));// } //Modified version: set to relative path (modify as needed) varSrcfixed =node.src; Srcfixed= Srcfixed.slice (Srcfixed.indexof (' upload '))); Srcfixed= ".. /.. /.. /.. /.. /" +srcfixed; returnArr.push ({//_src:node.src, //SRC:NODE.SR_src:srcfixed, src:srcfixed}); }); returnarr; },
In this way, the data stored in the database is the relative address, regardless of IP, domain name.
Umeditor Upload image relative path settings and save