1. Download The FCKeditor package
Fckeditor-java-2.4.1-bin.zip
Fckeditor_2.6.4.zip
: Http://www.fckeditor.net/download
2. Download The slf4j-1.5.2.zip package
: Http://slf4j.org/dist/
3. Extract the required files:
1. fckeditor-java-2.4.1-bin.zip unzip the four out of the commons-fileupload-1.2.1.jar, commons-io-1.3.2.jar, fckeditor-java-core-2.4.jar, and slf4j-api-1.5.2.jar to the Lib folder of the WEB-INF.
2. Decompress fckeditor_2.6.4.zip and put the FCKeditor folder under the root directory.
3. slf4j-1.5.2.zip unzip the slf4j-simple-1.5.2.jar to the Lib folder of the WEB-INF.
4. Create the attribute file FCKeditor. properties in classes. The content is connector. useractionimpl = net. FCKeditor. requestcycle. impl. useractionimpl.
5. Add the following information to Web. xml:
<Servlet>
<Servlet-Name> connector </servlet-Name>
<Servlet-class> net. FCKeditor. connector. connectorservlet </servlet-class>
<Load-on-startup> 1 </load-on-startup>
</Servlet>
<Servlet-mapping>
<Servlet-Name> connector </servlet-Name>
<URL-pattern>/FCKeditor/Editor/filemanager/connectors/* </url-pattern>
</Servlet-mapping>
Vi. Test Run
<% @ Taglib uri = "http://java.fckeditor.net" prefix = "fck" %>
For version 2.4.1, use the following
<Fck: Editor InstanceName = "editordefault">
The initial content to be displayed in the control.
</Fck: Editor>
For version 2.4, use the following
<Fck: Editor InstanceName = "default" value = "">
</Fck: Editor>
7. Solve the Problem of garbled characters After uploading Chinese Images
1. When a Chinese image is uploaded, the file name is garbled.
2. Chinese characters are garbled during Directory Creation
3. When the referenced image is text-oriented, it is displayed as a red cross on the page.
In this case, I feel like FCKeditor is a bug. It's not because we have the correct configuration. To solve the above three problems, we need to modify the source code of FCKeditor.
For problems 1 and 2, we can solve it in one way, and use UUID (this class is located in Java. util. UUID, you can check the API if you do not understand) to solve this problem. The idea is to randomly rename these uploaded Chinese names to English strings, so that there is no Chinese problem.
Because we cannot directly modify FCKeditor, We need to rewrite the servlet orservlet Servlet File. We create a class file in our project, name it connectorservlet, and directly put net. FCKeditor. connector. copy the contents of connectorservlet. In addition, you need to modify the Web. xml file to point the servlet to the servlet we have rewritten.
If we put the newly created connectorservlet under the test. FCKeditor package, Web. xml needs:
<Servlet-class>
Net. FCKeditor. connector. connectorservlet
</Servlet-class>
Change
<Servlet-class>
Test. FCKeditor. connectorservlet
</Servlet-class>
Keep others unchanged!
After we copy the file, an error is reported, indicating that messages cannot be found. We can use the eclipse repair function to import the net. FCKeditor. connector. Messages package.
Next, we will modify this servlet to solve the above three Chinese garbled characters.
First problem: Find the try... Catch Block in the dopost method. Add the following statement before try:
Upload. setheaderencoding ("UTF-8 ");
Here we encode this upload to solve the Chinese problem. After re-deploying the project, you will find that the pictures uploaded with Chinese names will not be garbled.
The second problem: Find
String newfolderstr = utilsfile. sanitizefoldername (Request
. Getparameter ("newfoldername "));
To:
String tempstr = request. getparameter ("newfoldername ");
Tempstr = new string (tempstr. getbytes ("iso8859-1"), "UTF-8 ");
String newfolderstr = utilsfile. sanitizefoldername (tempstr );
The original code does not recode the rerquest data, so garbled characters will appear in Chinese!
The third problem: there are actually two solutions. One is to modify the server URL encoding, but it is more convenient to modify the server on our own computer, it would not be easy for us to put it in our own space. In addition, if you modify the server code, it may affect other projects. So this method will not be written.
Second, we use UUID to rename the uploaded file to an English text string.
Find the first if in the try statement block in dopost:
If (! Extensionshandler. isallowed (resourcetype, extension ))
Ur = new uploadresponse (uploadresponse. SC _invalid_extension );
Add the following statement before this Code:
Filename = UUID. randomuuid (). tostring () + "." + extension; // extension is the extension.
In this way, all three of our problems are solved. If we do step 3, The first modification will have no effect, so if we use it, we can only perform Step 2 or three.