SoFunction
Updated on 2025-04-07

jsp fckeditor solution to the problem of uploading Chinese pictures garbled code

After I modified and two files, I regenerated the fckeditor-java-2. package. To solve all the garbled problems, there are 3 to modify.
1. Modify the character encoding of the web container. If the web container uses Tomcat, modify the conf/file and add "URIEncoding="utf-8"" to the two connectors. I use utf-8 encoding here, so modify it to utf-8. If the project is gb2312 encoding, set to "URIEncoding="gb2312"".
2. When uploading a file in the "Browse Server" page, open the file /editor/filemanager/browser/default/ in the project WebRoot and add a meta to the head: , see if the file is in utf-8 format, if not, convert it to utf-8. If you are not using utf-8, convert it to the encoding you use, and the above charset is also set to the encoding you use
3. Modify the two files. I added a static variable encoding, private static String encoding; save the encoding in the project. If the value is not passed to this variable in the file, the default is gb2312, the following code is if(()){encoding="gb2312";}, add (encoding) in the beginning of doGet and doPost; set the requested character set encoding to the encoding in the project, DiskFileUpload upload = new in the two files DiskFileUpload(); adds (encoding); tells the FileUpload component to process the encoding as project encoding. In FileItem, getString(encoding) is used. This setting can solve the problem that the obtained form fields are garbled. Therefore, getString(encoding) is executed after each FileItem instance, and tells FileItem to use the encoding when getting the value is the encoding set by encoding. For example, add a sentence (encoding) after the FileItem item in the two files; add a sentence (encoding) after the FileItem uplFile; Next is set, and pass the value of the encoding mentioned above, as follows
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
Everything is OK, and it really solved the problem of uploading Chinese name pictures garbled.
In the above step 3, you need to use Ant to generate jars. At this time, you should pay attention to copy the Tomcat installation directory in /server/lib to the project's /WEB-INF/lib. Open and modify property name="" to the Tomcat installation directory. Modify the taskdef name="deploy", taskdef name="list", taskdef name="reload", taskdef name="undeploy" as follows:
<taskdef name="deploy" classname="">
<classpath refid=""></classpath>
</taskdef>
<taskdef name="list" classname="">
<classpath refid=""></classpath>
</taskdef>
<taskdef name="reload" classname="">
<classpath refid=""></classpath>
</taskdef>
<taskdef name="undeploy" classname="">
<classpath refid=""></classpath>
</taskdef>
Then run Ant's dist in the Outline window of Eclipse, and the new FCKeditor-2 will be generated. It is definitely real. Share it with everyone. One less person to upload other files, such as RAR. If you have added this function, please share it.