您的位置:首页 > 理论基础 > 计算机网络

FCK编辑器在JSP中使用基本说明(来自http://blog.360quan.com/u/1281c9/show/506089)

2008-02-29 11:25 246 查看
步骤1:将fckeditor文件夹拷贝到/WebRoot目录下
步骤2:将lib文件夹下的两个jar文件拷贝到/WebRoot/WEB-INF/lib目录下
步骤3:将FCKeditor.tld文件拷贝到/WebRoot/WEB-INF目录下
步骤4:将Web.xml文件中的内容拷贝到工程的web.xml文件中,注意里面两个Servlet配置的路径修改

在JSP页面配置FCKeditor编辑器
/**
* 方法一:
*/
在JSP页面头部配置
<%@ page language="java" import="com.fredck.FCKeditor.*"%>
在<body>标签你想放置FCKeditor编辑器的地方配置
<%
// 获得上下文路径
String path = request.getContextPath();
FCKeditor oFCKeditor;
// 定义一个属性来使Action通过request来获得FCKeditor编辑器中的值
oFCKeditor = new FCKeditor(request, "content");
oFCKeditor.setBasePath(path + "/fckeditor/");
// 设置FCKeditor编辑器打开时的默认值
oFCKeditor.setValue("input 1111");
out.println(oFCKeditor.create());
%>

/**
* 方法二:
*/
在JSP页面头部配置
<%@ taglib uri="/MyFCKeditor" prefix="FCK"%>
注意这个uri,也可以写为"/WEB-INF/FCKeditor.tld",这里的写法其实是已经将tld文件配置在工程的web.xml文件中了
在<body>标签你想放置FCKeditor编辑器的地方配置
<FCK:editor id="content" <!-- 定义FCKeditor的标志,以便Action获得其值-->
       basePath="fckeditor/"     <!-- 注意这里为FCKeditor的基本路径,无需配置上下文路径-->
imageBrowserURL="/fckeditor/editor/filemanager/browser/default/browser.html?Type=Image&Connector=connectors/jsp/connector"
linkBrowserURL="/fckeditor/editor/filemanager/browser/default/browser.html?Connector=connectors/jsp/connector"
flashBrowserURL="/fckeditor/editor/filemanager/browser/default/browser.html?Type=Flash&Connector=connectors/jsp/connector">
this is default content :)
</FCK:editor>

Q:Action中如何获得FCKeditor中的内容?
A:很简单,上面两种方法对FCKeditor的标记都为content,在Action中用request.getParameter("content")即可。注意的是,这里获得的字符串是包括html标签的(即FCKeditor的值的HTML源代码)。

Q:FCKeditor中的按钮太多,只要其中一些该如何修改?
A:在fckconfig.js文件中修改,代码如下:
     FCKConfig.ToolbarSets["Default"] = [   
      ['Cut','Copy','Paste','PasteText','PasteWord','-','Print','SpellCheck'],   
      ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],   
      ['Bold','Italic','Underline','StrikeThrough','-','Subscript','Superscript'],   
      ['OrderedList','UnorderedList','-','Outdent','Indent'],   
      ['JustifyLeft','JustifyCenter','JustifyRight','JustifyFull'],   
      ['Link','Unlink','Anchor','Image','Flash'],   
      ['TextColor','BGColor','Table','Rule'],   
      ['Style','FontFormat','FontName','FontSize']   
      ] ;   
      将不用的删除即可。
Q:FCKedior中如何使用JavaScript来获得和设置其中的内容
A:<script type="text/javascript">
// 获得编辑器中的HTML内容
function getHTMLValue()
{
        var oEditor = FCKeditorAPI.GetInstance("content");
        var value = oEditor.GetXHTML(true);
        alert(value);
}
// 获得编辑器中的文本内容
function getTextValue()
{
        var oEditor = FCKeditorAPI.GetInstance("content");
        var value = oEditor.EditorDocument.body.innerText;
       alert(value);
}
// 设置编辑器中的内容
function initFCK()
{
        var oEditor = FCKeditorAPI.GetInstance("content");
       oEditor.SetHTML("<p><font color='red'>aaa</font></p>");
}
     </script>

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息