Integrating CKEditor into the Java development environment

Source: Internet
Author: User

This article mainly describes how to integrate CKEditor into the Java development environment, CKEditor is an upgraded version of FCKeditor, easy to use. Here are the basic usage methods:

First step: Download the necessary libraries

1, to ckeditor official website http://www.fckeditor.net/download/Download Ckeditor4.0.2, this is the latest version of the current, 4.1 immediately came out.

2. Find CKEditor 3.6.4 for Java, Download.jar button, download Ckeditor-java-core-3.5.3.zip, this is the Java Integrated jar package, can be used to configure CKEditor, which also has CKEditor label, it is more important.

The second step: Put the Ckeditor-java-core-3.5.3.jar and CKEditor library into the corresponding directory of the project, jar package into the LIB, library files (JS and other resource files) placed in the directory of the page resources, according to their own situation

3, in the need to use the editor JSP page to add ckeditor tag library, so that you can use the <ckeditor> tag

<%@ taglib uri= "http://ckeditor.com" prefix= "CKEditor"%>

4. If you let CKEditor automatically create an instance, simply add a <ckeditor:replace> before the </body> tag (the official recommendation is to do so and add it elsewhere)

<! DOCTYPE unspecified public "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" ><%@ Page pageencoding= "UTF-8" contenttype= "text/html; Charset=utf-8 "%><%@ taglib uri=" http://ckeditor.com "prefix=" CKEditor "%>


Note that replace in:<ckeditor:replace> corresponds to the id,basepath of the <textarea> tag that corresponds to the CKEditor resource file's storage path. If you need to replace multiple <textarea>, you can use the <ckeditor:replaceAll> label,

<ckeditor:replaceall basepath= "/ckeditor/" classname= "MyClass"/>

Where classname is the class style of <textarea>, as long as the <textarea> class style is MyClass, it will be replaced by CKEditor instances.

5. If you want to create a CKEditor instance manually, you can create it through the <ckeditor:editor> tag.

<ckeditor:editor textareaattributes= "<%=attr%>" basepath= "/ckeditor/" editor= "Editor1" value= "Type Here"/ >

Where BasePath is the CKEditor storage directory, editor is the global <textarea> element name,value is the default value of the <textarea>, textareaattributes corresponding <textarea> configuration information, is a JAVA.UTIL.HASHMAP type of object, key corresponding to the property name in the <textarea> name,value corresponding <textarea> The value of the property in.

<% map<string, string> attr = new hashmap<string, string> (), Attr.put ("Rows", "8"), Attr.put ("cols", "50") ;%>


6. Submit Editorial Content

Background to get edits and usually use <textarea> no difference, ckeditor just to enhance <textarea>, so data acquisition is still through the <textarea> Name property.

If you want to get the contents of the CKEditor instance in JS, you can get it through the CKEditor API.

var data = CKEDITOR.instances.editor1.getData ();

The basic process is this, if you want to modify the CKEditor style, you can modify the CKEditor resource file Config.js,

/*copyright (c) 2003-2011, Cksource-frederico Knabben. All rights reserved. For licensing, see license.html or http://ckeditor.com/license*/ckeditor.editorconfig = function (config) {//Define Chan GES to the default configuration here. For example://config.language = ' fr ';//Config.uicolor = ' #AADC6E '; config.language = ' ZH-CN '; Config language config.uicolor = ' #FFF '; Background color config.width = ' auto '; Width config.height = ' 300px '; Height Config.skin = ' office2003 ';//interface v2,kama,office2003 Config.toolbar = ' mytoolbar ';//toolbar style (basic ' basic ', almighty ' full ', custom Plugins/toolbar/plugin.js config.toolbarcancollapse = false;//toolbar can be shrunk config.resize_enabled = false;//Cancel "Drag to Resize "function plugins/resize/plugin.js//custom toolbar Config.toolbar_mytoolbar = [[' Source ', '-', ' Save ', ' Prev Iew ', ' Print ', [' Cut ', ' Copy ', ' Paste ', ' pastetext ', ' Pastefromword ', '-', ' Scayt '], [' Undo ', ' Redo ', '-', ' Find ', ' Re Place ', '-', ' selectall ', ' Removeformat '], [' Image ', ' Flash ', ' Table ', ' Horizon 'Talrule ', ' Smiley ', ' Specialchar ', ' pagebreak ', '/', [' Styles ', ' Format '], [' Bold ', ' Italic ', ' Strike '], [' Numberedlist ', ' BulletedList ', '-', ' outdent ', ' Indent ', ' Blockquote '], [' Link ', ' Unlink ', ' Anchor '], [' Max Imize ', '-', ' about '];};

You can also set it directly in the JSP:

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" UTF-8 "%><%@ page import=" Com.ckeditor.CKEditorConfig "%><%@ taglib uri=" Http://ckeditor.com "prefix=" CKEditor "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >

If you want to know more, you can refer to CKEditor's official website for instructions, http://docs.cksource.com/CKEditor_3.x/Developers_Guide/Java/Integration

The editor is generally easy to use and can meet general needs. Of course, this editor is developed abroad, there are better online editor, such as Kindeditor, Chinese display, seemingly use more than this is also simple, interested you can try, kindeditor official website: http://www.kindsoft.net/

Integrating CKEditor into the Java development environment

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.