Ckeditor3.5.3 integration in java web Applications

Source: Internet
Author: User

Integrate CKEditor3.5.3 online editor in OpenJWeb
 
QQ: 29803446
Baozhengw@163.com
 
 
Because fckeditor has been upgraded to ckeditor3.5.3, ckeditor3.5.3 is integrated in the openjweb platform. The original fckeditor2.6 is still available. This article describes how to integrate ckeditor into your web application.
Download ckeditor3.5.3 from the Internet and decompress it to the ckeditor directory of your web application.
 
I. font and font size
 
After ckeditor is integrated, if you need to customize the font list and font size, you need to open ckeditor under the ckeditor directory. js file, because ckeditor does not have Chinese fonts such as and by default, it can be found in ckeditor. find I. font_names =, modify the original I. font_names value, modified content:
I. font_names = u5b8bu4f53; u6977u4f53_GB2312; large; u9ed1u4f53; small; Arial Black; Arial; Comic Sans MS; Courier New; Tahoma; Times New Roman; Verdana ;;
 
Font size modification:
Find the sentence I. fontSize_sizes =, which defines the font size used by the editor:
I. fontSize_sizes = 8/8px; 9/9px; 10/10 px; 11/11 px; 12/12 px; 14/14 px; 16/16 px; 18/18 px; 20/20 px; 22/22 px; 24/24 px

26/26 px; 28/28 px; 36/36 px; 48/48 px; 72/72 px;
To increase or delete the font size, you can modify the I. fontSize_sizes value.
 
Ii. Editor buttons
 
If some buttons in the editor need to be hidden, you can modify the config. js file, in config. js,
Onfig. toolbar_A =
[
[Source],
[Cut, Copy, Paste, PasteText, PasteFromWord,-, Print, SpellChecker, Scayt],
[Undo, Redo,-, Find, Replace,-, SelectAll, RemoveFormat],
/,
[Bold, Italic, Underline, Strike,-, Subscript, Superscript],
[NumberedList, BulletedList,-, Outdent, Indent, Blockquote],
[JustifyLeft, JustifyCenter, JustifyRight, JustifyBlock],
[Link, Unlink, Anchor],
[Image, Table, HorizontalRule, Smiley, SpecialChar, PageBreak],
/,
[Styles, Format, Font, FontSize],
[TextColor, BGColor],
[Maximize, ShowBlocks]
];
This code is used to configure the editor tool button. '/' indicates a line break. Each pair of [] sets a group of buttons, and there is a separator between different groups of buttons.
 
3. upload files
 
Ckeditor no longer provides the Java version of the file upload and select files from the server, you need to implement it yourself. This section describes how to upload and browse server files.
First, specify the page for viewing server files and uploading files in config. js:
Config. filebrowserBrowseUrl =/portal/common/FileManager. jsp;
Config. filebrowserUploadUrl =/portal/common/uploadCK2.jsp;
Config. filebrowserImageUploadUrl =/portal/common/uploadCK2.jsp? Type = Images;
 
The page FileManager for browsing server files is specified above. jsp: The uploadCK2.jsp page for uploading files./portal indicates the name of the current web application, that is, request is used in jsp. the value obtained by getContextPath. The following is the uploadCK2.jsp code:
<% @ Page import = "java. io. File" %>
<% @ Page import = "java. util. UUID" %>
<% @ Page import = "org. apache. commons. fileupload. FileItem" %>
<% @ Page import = "java. util. List" %>
<% @ Page import = "org. apache. commons. fileupload. disk. DiskFileItemFactory" %>
<% @ Page import = "org. apache. commons. fileupload. FileItemFactory" %>
<% @ Page import = "org. apache. commons. fileupload. servlet. ServletFileUpload" %>
<% @ 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">
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<Meta http-equiv = "pragma" content = "no-cache">
<Meta http-equiv = "cache-control" content = "no-cache">
<Meta http-equiv = "expires" content = "0">
<Title> File Upload </title>
</Head>
<Body>
<%
 
String callback = request. getParameter ("CKEditorFuncNum ");
String relativePath = "/userfiles/image/"; // the uploaded file is stored in the/userfiles/image/directory of the web application. You can modify it as needed.
 
If (ServletFileUpload. isMultipartContent (request) // check whether the form type uploaded to this page is enctype = "multipart/form-data ".
{

String type = "";
If (request. getParameter ("type ")! = Null) // obtain the file category
Type = request. getParameter ("type"). toLowerCase () + "/";
FileItemFactory factory = new DiskFileItemFactory ();
ServletFileUpload servletFileUpload = new ServletFileUpload (factory );
ServletFileUpload. setHeaderEncoding ("UTF-8"); // solves the problem of garbled file names
List <FileItem> fileItemsList = servletFileUpload. parseRequest (request );
System. out. println (fileItemsList. size ());
For (FileItem item: fileItemsList)
{
If (! Item. isFormField ())
{
String fileName = item. getName ();
FileName = fileName. replace ("\","/");
String fullName = fileName;
FileName = fileName. substring (fileName. lastIndexOf ("/") + 1 );
// Save the file to the server
& N

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.