Application of FCKeditor in jsp Environment

Source: Internet
Author: User

The online editor is very important for programs such as news products. FCKeditor is a cross-platform tool.1. Download
FCKeditor. java 2.3 (FCKeditot for java)
FCKeditor 2.2 (FCKeditor basic file)
The following are:
Http://www.fckeditor.net/download/default.html

2. Create a project:
Create a project tomcat/webapps/TestFCKeditor.

3. Decompress FCKeditor2.2
Decompress FCKeditor2.2 and copy the entire FCKeditor directory to the project root directory,
Directory structure: tomcat/webapps/TestFCKeditor/FCKeditor
Then copy the two jar files in the \ web \ WEB-INF \ lib \ directory of the fckeditor-2.3.zip (java) Compressed package to the \ WEB-INF \ lib \ directory of the project. Copy the FCKeditor. tld file under the src directory to TestFCKedit/FCKeitor/WEB-INF /.

4. Merge web. xml:
Merge the web. xml file under the \ web \ WEB-INF \ directory of the fckeditor-2.3.zip package into the web. xml file under the \ WEB-INF \ directory of the project.


5. Modify the merged web. xml file
Modify the merged web. xml file and change the enabled parameter value of the Servlet named SimpleUploader to true,
To allow upload. The baseDir parameter value of Servlet ctor Servlet is used to set the location where the uploaded files are stored.
Add Tag definition:
<Taglib>
<Taglib-uri>/TestFCKeditor </taglib-uri>
<Taglib-location>/WEB-INF/FCKeditor. tld </taglib-location>
</Taglib>

Running diagram:



6. ing:
The mappings between the two servlets in the above file are:/editor/filemanager/browser/default/connectors/jsp/connector.
And/editor/filemanager/upload/simpleuploader, you need to add/FCKeditor before the two mappings,
Change to/FCKeditor/editor/filemanager/browser/default/connectors/jsp/connector and
/FCKeditor/editor/filemanager/upload/simpleuploader.

7. Modify the skin folder
Go to the skin folder. If you want to use the default fckeditor milk yellow,
Delete the other two folders except the default folder.

8. Delete useless files
Delete all files except fckconfig. js, FCKeditor. js, fckstyles. xml, and fcktemplates. xml in the/fckeditor/directory.
Delete directory/editor/_ source,
Delete all files under/editor/filemanager/browser/default/connectors/
Delete all files under/editor/filemanager/upload/
Delete all files under/editor/lang/Except for fcklanguagemanager. js, en. js, zh. js, zh-cn.js 4 files

9. Modify the Configuration:
Open/FCKeditor/fckconfig. js
Modify FCKConfig. DefaultLanguage = 'zh-cn ';
Replace the values of FCKConfig. LinkBrowserURL with the following:
FCKConfig. LinkBrowserURL
= FCKConfig. BasePath + "filemanager/browser/default/browser.html? Connector = connectors/jsp/connector ";

FCKConfig. ImageBrowserURL
= FCKConfig. BasePath + "filemanager/browser/default/browser.html? Type = Image & Connector = connectors/jsp/connector ";

FCKConfig. FlashBrowserURL
= FCKConfig. BasePath + "filemanager/browser/default/browser.html? Type = Flash & Connector = connectors/jsp/connector ";

FCKConfig. LinkUploadURL = FCKConfig. BasePath + 'filemanager/upload/simpleuploader? Type = FILE ';
FCKConfig. FlashUploadURL = FCKConfig. BasePath + 'filemanager/upload/simpleuploader? Type = Flash ';
FCKConfig. ImageUploadURL = FCKConfig. BasePath + 'filemanager/upload/simpleuploader? Type = image ';

10. Others
Fckconfig. js configuration file, which can be opened in the log book. After modification, the file will be saved as UTF-8 encoding format. Find:

Change FCKConfig. TabSpaces = 0; To FCKConfig. TabSpaces = 1; that is, you can use the Tab key in the editor.

If your editor is still used at the front-end of the website, for example, when it is used for message book or diary reply, you have to consider security,
Do not use the Default toolbar on the front-end, either customize the function or use the Basic defined by the system,
That is, the basic toolbar. Find:
FCKConfig. ToolbarSets ["Basic"] = [
['Bold ', 'italic', '-', 'orderedlist', 'unorderedlist', '-',/* 'link', */'unlink ', '-', 'style', 'fontsize', 'textcolor', 'bgcolor ','-',
'Smilil', 'specialchar ', 'replace', 'preview'];
This is a modified Basic. Remove the image function and the Add link function, because the image and link and flash and image button add function can make the foreground
Page to directly access and upload files. fckeditor also supports the right-click function in the editing area.

FCKConfig. contextMenu = ['generic',/* 'link', */'anchor ',/* 'image', */'flash', 'select', 'textarea ', 'checkbox', 'Radio ', 'textfield', 'hiddenfield ',
/* 'Imagebutton ', */'button', 'bulletedlist', 'numberedlist', 'tablecell ', 'table', 'form'];

This is also a change to remove the "link, image, FLASH, image button" function of the right mouse button.

Find: FCKConfig. FontNames = 'arial; Comic Sans MS; Courier New; Tahoma; Times New Roman; Verdana ';
Add several common Fonts
FCKConfig. FontNames
= '; _ GB2312; Arial; Comic Sans MS; Courier New; Tahoma; Times New Roman; Verdana ';

11. Add a file
Add the file/TestFCKeditor/test. jsp:
<% @ Page language = "java" import = "com. fredck. FCKeditor. *" %>
<% @ Taglib uri = "/TestFCKeditor" prefix = "FCK" %>
<Script type = "text/javascript" src = "/TestFCKeditor/FCKeditor/fckeditor. js"> </script>

<% --
Three methods to call FCKeditor
1. FCKeditor custom tag (header file must be added <% @ taglib uri = "/TestFCKeditor" prefix = "FCK" %>)
2. script Language call (the script file <script type = "text/javascript" src = "/TestFCKeditor/FCKeditor/fckeditor. js"> </script> must be referenced)
3. FCKeditor API call (header files must be added <% @ page language = "java" import = "com. fredck. FCKeditor. *" %>)
-- %>

<% --
<Form action = "show. jsp" method = "post" target = "_ blank">
<FCK: editor id = "content" basePath = "/TestFCKeditor/FCKeditor /"
Width = "700"
Height = "500"
SkinPath = "/TestFCKeditor/FCKeditor/editor/skins/silver /"
ToolbarSet = "Default"
>
Input
</FCK: editor>
<Input type = "submit" value = "Submit">
</Form>
-- %>

<Form action = "show. jsp" method = "post" target = "_ blank">
<Table border = "0" width = "700"> <tr> <td>
<Textarea id = "content" name = "content" style = "WIDTH: 100%; HEIGHT: 400px"> input </textarea>
<Script type = "text/javascript">
Var oFCKeditor = new FCKeditor ('content ');
OFCKeditor. BasePath = "/TestFCKeditor/FCKeditor /";
OFCKeditor. Height = 400;
OFCKeditor. ToolbarSet = "Default ";
OFCKeditor. ReplaceTextarea ();
</Script>
<Input type = "submit" value = "Submit">
</Td> </tr> </table>
</Form>

<% --
<Form action = "show. jsp" method = "post" target = "_ blank">
<%
FCKeditor oFCKeditor;
OFCKeditor = new FCKeditor (request, "content ");
OFCKeditor. setBasePath ("/TestFCKeditor/FCKeditor /");
OFCKeditor. setValue ("input ");
Out. println (oFCKeditor. create ());
%>
<Br>
<Input type = "submit" value = "Submit">
</Form>
-- %>

Add file/TestFCKeditor/show. jsp:
<%
String content = request. getParameter ("content ");
Out. print (content );
%>

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.