08-04
28

FCK配置及扩展攻略

    本文的主要的特点就是考虑到了两个平台:linux和windos;考虑了两个服务器:apache和resin。主要讲述了里面的配置方法和测试用例,并没有详细的讲述什么瘦身,什么其他安全配置等等。

    本文的修改针对的是resin3.0和apache2.2;windows xp(本机)和redhat AS4(具有特定配置的修改)。具体的配置方法如下:

1、安装包选择

本次配置中使用了FCKeditor2.6和FCKeditor.java 2.3。可以在http://www.fckeditor.net/download下载得到。

2、初步配置

(1)在webapp下新建项目FCKeditor

在该项目下新建WEB-INF文件夹,然后将FCKeditor.java 2.3解压,把其中的web/WEB-INF目录copy到FWEB-INF下(里面有commons-fileupload.jar, FCKeditor-2.3.jar,web.xml几个文件;注意,然后我们要把 FCKeditor-2.3.jar包删除,否则修改源代码时,将不会编译);

把其中的src目录下的FCKeditor.tld文件copy到WEB-INF//tld下 (tld为自己新建目录);

把src文件下的com包copy到WEB-INF\classes中,以方便修改;

(2)修改web.xml:
把SimpleUploader中的配置属性enabled定义为true(开启文件上传功能)
添加标签定义:
<taglib>
<taglib-uri>/FCKeditor</taglib-uri>
<taglib-location>/WEB-INF/tld/FCKeditor.tld</taglib-location>
</taglib>



(3)解压FCKeditor2.6后,把目录/editor和fckconfig.js, fckeditor.js, fckstyles.xml, fcktemplates.xml四个文件copy到/FCKeditor下;

打开/FCKeditor/fckconfig.js
修改 FCKConfig.DefaultLanguage = 'zh-cn' ;
把FCKConfig.LinkBrowserURL等的值替换成以下内容:
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' ;


3、初步测试

在FCKeditor中新建test.jsp和show.jsp

test.jsp如下(代码很长,但是里面注释掉的东西很多,主要是为了以后使用方便):

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

<%@ page language="java" import="com.fredck.FCKeditor.*" %>

<%@ taglib uri="/WEB-INF/tld/FCKeditor.tld" prefix="FCK" %>

<script type="text/javascript" src="fckeditor.js"></script>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%
String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<base href="<%=basePath%>">


<title>My JSP 'test.jsp' starting page</title>


</head>

<body>

<!--

<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 = "/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">

<FCK:editor id="content" basePath="/FCKeditor/" width="700" height="500" skinPath="/FCKeditor/editor/skins/silver/"

toolbarSet = "Default" >

input

</FCK:editor>

<input type="submit" value="Submit">

</form>

<!--

<form action="show.jsp" method="post" target="_self">

<%

//FCKeditor oFCKeditor ;

//oFCKeditor = new FCKeditor( request, "content" ) ;

//oFCKeditor.setBasePath( "/FCKeditor/" ) ;

//oFCKeditor.setValue( "input" );

//out.println( oFCKeditor.create() ) ;

%>

<br>

<input type="submit" value="Submit">

</form>

-->

</body>

</html>


特别说明开头的编码设置

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>


是为jsp容器指明编码方式;而<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">仅仅是显示的指明html文档的显示方式;

show.jsp代码如下:


<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>



<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<base href="<%=basePath%>">


<title>My JSP 'show.jsp' starting page</title>


</head>


<body>

<%

request.setCharacterEncoding("UTF-8");

String content = request.getParameter("content");

out.print(content);

%>

</body>

</html>



4、问题的解决:


修改com.fredck.FCKeditor.connector中的ConnectorServlet.java文件。


最开始变量声明时,增加一个os类型的声明,本例中使用了

private static String os = new String("Linux");



DoGet方法中,
① 、String currentFolderStr=request.getParameter("CurrentFolder"); 改为

String currentFolderStrTemp=request.getParameter("CurrentFolder");

String currentFolderStr = new String(currentFolderStrTemp.getBytes("ISO8859-1"),"utf-8");


这里主要是因为这里获得的currentFolderStr不是utf-8的编码方式,更改后为utf-8编码;




②、 String newFolderStr=request.getParameter("NewFolderName");

前面加上:request.setCharacterEncoding("utf-8");

本句改为:String newFolderStrTemp=request.getParameter("NewFolderName");

后面加上:String newFolderStr = new String(newFolderStrTemp.getBytes("ISO8859-1"),"utf-8");继续进行编码方式转换;



doPost方法中,

③ 、String currentPath=baseDir+typeStr+currentFolderStr;

改为 String currentPathTemp=baseDir+typeStr+currentFolderStr;

并且在后面加上:

String currentPath=new String(currentPathTemp.getBytes("ISO8859-1"),"utf-8");进行显性编码转换;




④、DiskFileUpload upload = new DiskFileUpload();

后面加上如下语句:

java.util.Properties props=System.getProperties();

if(os.equalsIgnoreCase(props.getProperty("os.name"))){

upload.setHeaderEncoding("utf-8");

}


这里主要是针对文件上传的处理;


5、其他说明:

FCKConfig.TabSpaces = 1 ;


这里可以设置为1,也可以设置为0;1表示在编辑器中可以使用tab键。否则表示不可以使用;

FCKConfig.FontNames = 'Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana' ;


可以更改为

FCKConfig.FontNames = '宋体;黑体;隶书;楷体_GB2312;Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana' ;


添加几种常见的字体;

本配置方法针对了特定的系统和配置,并不能保证对所有的系统平台有效;核心部分是对java的更改。


文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: FCK 配置 扩展
相关日志:
评论: 0 | 引用: 0 | 查看次数: 1030
发表评论
昵 称:
密 码: 游客发言不需要密码.
内 容:
验证码: 验证码
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 1000 字 | UBB代码 开启 | [img]标签 关闭