1. 下载fckeditor-java-demo-2.6.war和fckeditor-java-2.6-bin.tar.gz
下载地址: http://sourceforge.net/projects/fckeditor/files/FCKeditor.Java/2.6/
2. 解压fckeditor-java-demo-2.6.war, 获取以下资源
主目录下的: fckeditor文件夹
lib目录下的:
commons-fileupload-1.2.1.jar
commons-io-1.3.2.jar
imageinfo-1.9.jar
java-core-2.6.jar
slf4j-api-1.5.8.jar
slf4j-simple-1.5.8.jar
WEB-INF\classes目录下的:
fckeditor.properties
web.xml中的:
<servlet> <servlet-name>ConnectorServlet</servlet-name> <servlet-class> net.fckeditor.connector.ConnectorServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>ConnectorServlet</servlet-name> <!-- Do not wrap this line otherwise Glassfish will fail to load this file --> <url-pattern>/fckeditor/editor/filemanager/connectors/*</url-pattern> </servlet-mapping>
3. 建立web项目sample
将fckeditor文件夹sample\WebContent\plugins\fckeditor
在lib中放入
commons-fileupload-1.2.1.jar
commons-io-1.3.2.jar
imageinfo-1.9.jar
java-core-2.6.jar
slf4j-api-1.5.8.jar
slf4j-simple-1.5.8.jar
在sample\src中放入(eclipse自动编译后会到classes目录下)
fckeditor.properties
在web.xml中加入
<servlet> <servlet-name>ConnectorServlet</servlet-name> <servlet-class> net.fckeditor.connector.ConnectorServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>ConnectorServlet</servlet-name> <!-- Do not wrap this line otherwise Glassfish will fail to load this file --> <url-pattern>/plugins/fckeditor/editor/filemanager/connectors/*</url-pattern> </servlet-mapping>
4. 调整配置
fckeditor.properties
# allow client upload file to server connector.userActionImpl=net.fckeditor.requestcycle.impl.EnabledUserAction # user can see path connector.userFilesPath=/userfiles/fckeditor # user can store path connector.userFilesAbsolutePath=/userfiles/fckeditor # the default path of the editor fckeditor.basePath=/plugins/fckeditor
fckconfig.js
FCKConfig.AutoDetectLanguage = false ; FCKConfig.DefaultLanguage = 'zh-cn' ; // 可以加入自定义的工具栏 // custom your Toolbar and use it FCKConfig.ToolbarSets["Custom"] = [ ['Bold','Italic','-','OrderedList','UnorderedList','-','Link','Unlink'] ] ;
5. 使用
fckeditor.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.fckeditor.net" prefix="FCK"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>use FCKeditor</title> </head> <body> <form action="commit.jsp" method="post" target="_blank"> <FCK:editor instanceName="EditorDefault" toolbarSet="Default" height="300" width="98%" > <jsp:attribute name="value"> This is some <strong>sample text</strong>. You are using <a href="http://www.fckeditor.net">FCKeditor</a>. </jsp:attribute> </FCK:editor> </body> </html>
commit.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <% String content = request.getParameter("EditorDefault"); %> <div> <%= content%> </div>
6. 关于中文文件名问题, 在此重写代码, 自定义文件名.
这个fckeditor-java-2.6-bin.tar.gz包中有源码, 获取Dispatcher.java, 建立相应的包名net.fckeditor.connector
调整代码如下:
UploadResponse doPost(final HttpServletRequest request) { logger.debug("Entering Dispatcher#doPost"); Context context = ThreadLocalData.getContext(); context.logBaseParameters(); UploadResponse uploadResponse = null; // check permissions for user actions if (!RequestCycleHandler.isFileUploadEnabled(request)) uploadResponse = UploadResponse.getFileUploadDisabledError(); // check parameters else if (!Command.isValidForPost(context.getCommandStr())) uploadResponse = UploadResponse.getInvalidCommandError(); else if (!ResourceType.isValidType(context.getTypeStr())) uploadResponse = UploadResponse.getInvalidResourceTypeError(); else if (!UtilsFile.isValidPath(context.getCurrentFolderStr())) uploadResponse = UploadResponse.getInvalidCurrentFolderError(); else { // call the Connector#fileUpload ResourceType type = context.getDefaultResourceType(); FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); try { List<FileItem> items = upload.parseRequest(request); // We upload just one file at the same time FileItem uplFile = items.get(0); // Some browsers transfer the entire source path not just the // filename String fileName = FilenameUtils.getName(uplFile.getName()); // rename file name logger.debug("old file name: " + fileName); fileName = dateFmt(new Date(), "yyyyMMdd") + "_" + UUID.randomUUID().toString().replace("-", "") + "." + getExtension(fileName); logger.debug("rename file name: " + fileName); logger.debug("Parameter NewFile: {}", fileName); // check the extension if (type.isDeniedExtension(FilenameUtils.getExtension(fileName))) uploadResponse = UploadResponse.getInvalidFileTypeError(); // Secure image check (can't be done if QuickUpload) else if (type.equals(ResourceType.IMAGE) && PropertiesLoader.isSecureImageUploads() && !UtilsFile.isImage(uplFile.getInputStream())) { uploadResponse = UploadResponse.getInvalidFileTypeError(); } else { String sanitizedFileName = UtilsFile.sanitizeFileName(fileName); logger.debug("Parameter NewFile (sanitized): {}", sanitizedFileName); String newFileName = connector.fileUpload(type, context.getCurrentFolderStr(), sanitizedFileName, uplFile.getInputStream()); String fileUrl = UtilsResponse.fileUrl(RequestCycleHandler.getUserFilesPath(request), type, context.getCurrentFolderStr(), newFileName); if (sanitizedFileName.equals(newFileName)) uploadResponse = UploadResponse.getOK(fileUrl); else { uploadResponse = UploadResponse.getFileRenamedWarning(fileUrl, newFileName); logger.debug("Parameter NewFile (renamed): {}", newFileName); } } uplFile.delete(); } catch (InvalidCurrentFolderException e) { uploadResponse = UploadResponse.getInvalidCurrentFolderError(); } catch (WriteException e) { uploadResponse = UploadResponse.getFileUploadWriteError(); } catch (IOException e) { uploadResponse = UploadResponse.getFileUploadWriteError(); } catch (FileUploadException e) { uploadResponse = UploadResponse.getFileUploadWriteError(); } } logger.debug("Exiting Dispatcher#doPost"); return uploadResponse; } /** * get extend of file name * * @param fileName * @return */ private String getExtension(String fileName) { return fileName.substring(fileName.lastIndexOf(".") + 1); } /** * format Date to String * * @param mydate * @param strDate * @return */ private String dateFmt(Date mydate, String strDate) { if (mydate == null) { return ""; } java.text.SimpleDateFormat df = new java.text.SimpleDateFormat(strDate); return df.format(mydate); }
7. 此时日志有info信息输出,控制日志输出.
删除lib目录下的: slf4j-simple-1.5.8.jar
同时添加:
slf4j-log4j12-1.5.8.jar
log4j-1.2.16.jar
在sample\src中放入(eclipse自动编译后会到classes目录下)log4j.properties
log4j.rootLogger=error, stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=(%F:%L) - %m%n
代码中的颜色不知道怎么设置, 没标出具体区别, 见谅.
相关推荐
3. **配置TLD文件**: 将`FCKeditor.tld`文件拷贝到`/WebRoot/WEB-INF`目录下,这个文件是Tag Library Descriptor,用于JSP中使用FCKeditor标签。 4. **配置Web.xml**: 将提供的`Web.xml`文件内容整合到工程的`web....
jsp 程序调用fckeditor2.6 版本的 小例子 本人发现fckeditor2.6加 fckeditor for 2.3 的时候在上传中文文件的时候会出现乱码 所以本人...哈哈 lib 下的 FCK2.6.JAR 是我重新打的包 <br>qq 交流 361619004
本实例主要围绕“fck+jsp+java”的结合,展示了如何在Java Web应用中集成并使用FCKeditor。 FCKeditor是一款基于JavaScript的富文本编辑器,它提供了丰富的文本格式化选项,如字体、字号、颜色、对齐方式、插入图片...
### Struts2项目中JSP页面使用FCKeditor详解 #### 一、引言 FCKeditor是一款功能强大的在线富文本编辑器,广泛应用于各种Web应用程序中,特别是那些需要用户输入格式化文本的场景。在Struts2项目中集成FCKeditor...
**FCKeditor 2.6** 是一个历史悠久且广受欢迎的开源在线文本编辑器,尤其在Web开发领域中被广泛应用。这款编辑器以其强大的功能、易用性和良好的跨平台兼容性而著称,支持多种服务器端技术,如JSP、ASP、ASPX和PHP。...
描述中提到的“fck2.6内核,fck for java 2.4”是指FCKeditor的一个特定版本,即2.6核心,与Java平台的2.4版本结合使用。FCKeditor 2.6是该编辑器的一个重要版本,它包含了丰富的文本格式化选项,如字体、字号、颜色...
例如,在 JSP 页面中使用如下代码: ```jsp <%@ taglib uri="http://java.fckeditor.net" prefix="FCK" %> <FCK:editor instanceName="myEditor" basePath="/fckeditor" value="this is the value" /> ``` 其中 `...
2. **初始化编辑器**:在需要使用FCKeditor的JSP页面中,通过JavaScript引入FCKeditor,并设置编辑器的基本属性,如宽度、高度等。例如: ```jsp <script type="text/javascript" src="/fckeditor/fckeditor.js">...
1. **跨平台支持**:FCKeditor 2.5支持多种服务器端环境,包括Java(JSP)、Active Server Pages(ASP)、PHP以及.NET等,这使得它能在各种Web应用程序中灵活使用。 2. **富文本编辑**:FCKeditor提供了一个完整的...
- **作用:** 决定是否在 Gecko 浏览器中使用 SPAN 标签代替 B、I 和 U 标签。 #### 53. `FCKConfig.StartupFocus = true/false;` - **说明:** 启动时焦点开关。 - **作用:** 与第二十五个相同,用于决定编辑器...