SSH system, Ueditor1.4.3 Editor configuration, add image deletion function + database storage

Source: Internet
Author: User

Release Notes: Ueditor editor 1.4.3JSP, UTF-8 version
Rookie use on the way encountered a lot of difficulties, in the Internet to find solutions, sorting out available for use, there are good suggestions on the better.
My goal:
    • The Ueditor editor is embedded in its original project;
    • Can only add can not delete pictures, useless resources occupy very unreasonable space, so in the multi-image upload and online management to add the ability to delete pictures;
    • Storing editor edits to an Oracle database
Steps
First, add the Ueditor Editor on the JSP interface
After downloading the text after decompression, the entire Ueditor1_4_3-utf8-jsp folder pasted into the project/webroot/js , the folder renamed to Ueditor.
  1. ueditor\jsp\ LIB below 5 jar packages are clipped to the project's Lib package, pay special attention to 2 of these jar packages: the Commons-io-2.4.jar project must not have a lower jar package than his version, such as Commons-io-1.x.jar or 2.0.jar, the lower version must be deleted; Ueditor-1.1.1.jar The official itself has a problem with the jar package, using an absolute path instead of a relative path. The attachment is as follows Ueditor-1.1.1.jar  | | | | | | | Note: The workaround for Ueditor-1.1.1.jar is to learn from the "JSP version ueditor picture online management return absolute path" article, its jar is JRE1.7 compiled, and mine is 1.6, incompatible. Accessories I compiled with jre1.6, if you want to use 1.7, please see the original article.
  2.  1 <script type= "text/ JavaScript "src=" ${ctx}/js/ueditor/ueditor.config.js "></script>2 <script type=" Text/javascript "src=" $ {ctx}/js/ueditor/ueditor.all.min.js "></script>3 <link rel=stylesheet href=" ${ctx}/js/ueditor/themes/ Default/css/ueditor.css " 
  3. Add an editor in the <body></body> where you want
    1 <script id= "editor" type= "Text/plain" style= "width:800px;height:500px;" > content, or read from a database </script>   

    At the same time, add the following code, instantiate the editor

    1 <script type= "Text/javascript" >    2     //instantiation Editor 3     </span>var UE = ue.geteditor (' editor '); 4 </ Script>

At this time, you can see the editor in the interface.

Second, the configuration editor, upload pictures and files, etc.

  1. The toolbars content in Ueditor.config.js represents the features that will be displayed, such as font color, size, etc., which you do not want to annotate yourself.
  2. Configure picture file path: ueditor.config.js Note content window.ueditor_home_url = "/xxxx/xxxx/";
    1 "window. Ueditor_home_url =/project name/js/ueditor/";
    That is, the path to the Ueditor folder while removing the comment.
  3. Ueditor\jsp\config.json, picture upload path
    1 "imageurlprefix": "/Change to Project name",/* Image access Path prefix */2 "Imagepathformat": "/js/ueditor/upload/image/{yyyy}-{mm}-{dd}/{time}_{ Rand:6}_{filename} ",/* picture storage path, and naming method */
    In the same Config.json, the others are changed, uploading files, listing pictures or files in the specified directory, etc.
  4. Try uploading the pictures successfully. If it fails, check to see if the picture exists under the folder deployed under Tomcat, and then analyze the reason. Ueditor picture does not display One reason: The uploaded picture name is the Chinese character.

Third, storage editing content

  1. JSP Interface settings Save button,
    1 var editortext = $.trim (ue.geteditor (' Editor '). getcontent ());
    Click Save to trigger the Ajax event, pass the data editortext to the Web layer Xxxxaction.java, and then call the service layer, then to the DAO layer and some other processes.
  2. Storage-related issues: Because of the large amount of data, the Oracle database takes a field of type Clob. The DAO layer SQL statement is an UPDATE statement, and the statement is too long for Oracle error ora-1704:string literal too long. Bothered me for a long time, online said the way
    1 Declare  v_clob CLOB: = ' big data '; 2 begin  INSERT into EDITOR values (' 2 ', V_clob); 3 end;
    Also , the final plan: to intercept the data, for example, cut into 4 paragraphs, the first update
    1 declare2   v_clob clob: = ' Big Data ' 3 begin4   update EDITOR Set editor_text = Editor_text where xxx;5 end;  
    The following paragraphs
    1 declare2   v_clob clob: = ' Big Data ' 3 begin4   update EDITOR Set editor_text = editor_text| | V_clob where Xxx;5 end;  
    success.
  3. When storing the editor content, the &xx cannot be stored . Processing method: Replace & with special character, and replace it later when reading. The interface does not allow this special character to be entered

Iv. ueditor Multi-image upload and online management added the ability to delete pictures. Similarly, file deletion is available

  1. Add code in ueditor->dialogs->image->image.html
     1 <script> 2//new online management Delete picture 3 function Uedel (path, id) {4 if (Confirm (' Are you sure you want to delete it? Not recoverable after deletion! ') {5//var url = editor.getopt (' Imagedelurl '); 6 deletefile (path); 7 var u    RL = editor.getopt (' Imagedelurl ');                     8 $.get (url,{' path ':p ath},function (data) {9 if (data.state = = ' success ') {10                   alert (data.message); $ ("#" +id). Parent ("Li"). Remove ();            }ELSE{13 alert (data.message),}15}, ' json ');             +} + function DeleteFile (path) {$.ajax ({type: ' POST ', 21             Url:editor.getOpt (' imagedelurl ') + ' action path: Method path for your Project Web layer processing!deletefile.action ', data:{pathname:path},23 cache:false,24 timeout:6000,25 error:function (XMLHttpRequest, Textstatus, Errorthrow N) {$ aleRT (' delete failed ');},28 success:function () {alert (' Delete succeeded! Please click Save to see if it is deleted by mistake!        '); Location.reload (); 31} 32}); }34 </script>

  2. Add code in Ueditor\jsp\config.json
    1/* Delete the file or picture under the specified directory */2      "Imagedelurl": "/Project Name",
  3. Web Layer processing method. Java Add the following method
    1 public     void DeleteFile () {2         //Picture and file Management Delete         3         String path = Servletactioncontext.getservletcontext () . Getrealpath (""). ReplaceAll ("\\\\", "/"); 4         System.out.println ("========================================path:" +path); 5         httpservletrequest Request = Struts2utils.getrequest (); 6         String pathName = this.getqueryparameter (Request, "PathName");             7                String FilePath = path  + pathName;       8 file         file = new file (FilePath); 9         //If the file path file exists and is a file, delete the         if (file.exists ()) {             One File.delete ();             System.out.println ("delete succeeded");            All         else {             System.out.println ("file does not exist");         }16     }

Five, debugging Tips

Chrome browser Ctrl+shift+n into stealth mode, no longer worry about the impact of JS cache.

SSH system, Ueditor1.4.3 Editor configuration, add image deletion function + database storage

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.