日期:2014-05-16  浏览次数:20328 次

FCKeditor 2.6.6的jsp使用

废话不多说,都是我个人的搭建步骤,仅供参考

?

1. 下载FCKeditor_2.6.6.zip、fckeditor-java-2.6-bin.zip、fckeditor-java-2.6-src.zip(要修改源码)、fckeditor-java-demo-2.6.war。

?

2.把FCKeditor_2.6.6.zip解压到WebRoot下;把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(这些jar包可以从war中获得)放到WEB-INF的lib下;把fckeditor.properties(可以从war中获得或是参考文档)放到src中。

?

3.编写fckeditor_index.jsp:(我用的是jsp标签的方式,还有javascript的方式,网上很多)

?

<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.fckeditor.net" prefix="FCK" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>Insert title here</title>
		<script type="text/javascript">
</script>
	</head>
	<body>
		<form action="fckeditor_index.jsp" method="post">
			<FCK:editor instanceName="MyFCKeditor" basePath="/fckeditor" value=" " toolbarSet="myToolbar"></FCK:editor>
			<input type="submit" value="提交" />
		</form>
		<%
		request.setCharacterEncoding("utf-8");
		String myFCKeditor=request.getParameter("MyFCKeditor");   %>
		<%=myFCKeditor %>
	</body>
</html>
?

4.编写myconfig.js放在fckeditor目录下

?

FCKConfig.DefaultLanguage = 'zh-cn' ;
FCKConfig.FontNames	= '宋体;楷体;隶书;黑体;Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana' ;
FCKConfig.EnterMode = 'br' ;			// p | div | br
FCKConfig.ShiftEnterMode = 'p' ;	// p | div | br
FCKConfig.ToolbarSets["myToolbar"] = [
	['Source','DocProps','-','Save','NewPage','Preview','-','Templates'],
	['Cut','Copy','Paste','PasteText','PasteWord','-','SpellCheck'],
	['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
	['Form','Checkbox','Radio','TextField','Textarea','Select','Button','ImageButton','HiddenField'],
	'/',
	['Bold','Italic','Underline','StrikeThrough','-','Subscript','Superscript'],
	['OrderedList','UnorderedList','-','Outdent','Indent','Blockquote','CreateDiv'],
	['JustifyLeft','JustifyCenter','JustifyRight','JustifyFull'],
	['Link','Unlink','Anchor'],
	['Image','Flash','Table','Rule','Smiley','SpecialChar','PageBreak'],
	'/',
	['Style','FontFormat','FontName','FontSize'],
	['TextColor','BGColor'],
	['FitWindow','ShowBlocks','-','About']		// No comma for the last row.
] ;

?

5.修改fckconfig.js中的

?

FCKConfig.CustomConfigurationsPath = FCKConfig.EditorPath + 'myconfig.js' ;

?

6.web.xml中加入(net.fckeditor.connector.ConnectorServlet是后面要改的

?

<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>
		<url-pattern>
        /fckeditor/editor/filemanager/connectors/*
      </url-pattern>
	</servlet-mapping>
?

7.运行应该可以看到fckeditor的编辑界面了,但这时上传文件中如果含有中文或是建立中文名的目录都会有乱码或是中文名文件无法用到,就要修改源码了。

?

8.在src中建立三个java文件:

com.wujay.ConnectorServlet.java与java-core-2.6.jar中net.fckeditor.connector.ConnectorServlet.java基本一样,只是其中的Dispatcher引用的是下面改版的:

com.wujay.Dispatcher.java与java-core-2.6.jar中net.fckeditor.connector.Dispatcher.java基本一样,只是在doGet方法中的