您的位置:首页 > Web前端 > JavaScript

JSP下FCKeditor的安装与使用

2008-02-03 15:18 357 查看
首先下载并解压最新的FCKeditor到各自的目录,一个是FCKeditor的核心文件,另一个是针对jsp的文件包
下载地址:http://www.fckeditor.net/download

接下来我们可以开始配置了。
我是在Jbuilder下来配置的
环境:
jdk:1.5

Tomcat:5.5.9

Jbuilder:2006
FCKeditor :FCKeditor_2.5.1
FCKeditor.java:FCKeditor-2.3

1.新建一个Web Module工程,我这里取名为FCKWeb 。

2.把FCKeditor_2.5.1目录下的FCKeditor目录拷贝到FCKWeb 工程的根目录,即FCKWeb 目录下。(注意:版本2.5.1解压后目录名为"fckeditor",需要改为FCKeditor)

3.将FCKeditor-2.3/web/WEB-INF目录下的web.xml中的两个servlet,servlet-mapping定义复制到工程的web.xml文件中去。

4.修改web.xml文件


<servlet-mapping>
<servlet-name>Connector</servlet-name>
<url-pattern>/editor/filemanager/browser/default/connectors/jsp/connector</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>SimpleUploader</servlet-name>
<url-pattern>/editor/filemanager/upload/simpleuploader</url-pattern>
</servlet-mapping>
  为

<servlet-mapping>
<servlet-name>Connector</servlet-name>
<url-pattern>/FCKeditor/editor/filemanager/browser/default/connectors/jsp/connector</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>SimpleUploader</servlet-name>
<url-pattern>/FCKeditor/editor/filemanager/upload/simpleuploader</url-pattern>
</servlet-mapping>
这里的/FCKeditor/是对应你FCKWeb 目录下的FCKeditor目录。
5.拷贝FCKeditor-2.3/web/WEB-INF/lib下的两个jar包到FCKWeb /WEB-INF/lib目录下,并在Jbuilder工程"Required Libraries"中配置。

6.在FCKWeb 目录下新建一个jsp,使用默认的MyJsp.jsp即可。

7. 文件开头处加入 :
<%@ taglib uri="http://fckeditor.net/tags-fckeditor" prefix="FCK" %>

8.在jsp中嵌入的代码:在Jsp中使用
方法一:(可能会出现:The requested resource (/FCKeditor/editor/fckeditor.html) is not available,因为基本路径设置错误。)
<c:set var="basepath"><c:url value="/fck/" /></c:set>
<FCK:editor id="descn" basePath="${basepath}" height="500px">
<c:out value="${book.descn}" escapeXml="false" default="" />
</FCK:editor>

方法二:
<FCK:editor id="infoContent" basePath="/FCKWeb /FCKeditor/"
width="800"
height="300"
>
请输入内容
</FCK:editor>

9.部署好工程,开启tomcat,打开MyJsp.jsp页面即可。

10.三种方法调用FCKeditor
<%--
三种方法调用FCKeditor
1.FCKeditor自定义标签 (必须加头文件 <%@ taglib uri="/TestFCKeditor" prefix="FCK" %> )
2.script脚本语言调用 (必须引用 脚本文件 <script type="text/javascript" src="/TestFCKeditor/FCKeditor/fckeditor.js"></script> )
3.FCKeditor API 调用 (必须加头文件 <%@ page language="java" import="com.fredck.FCKeditor.*" %> )
--%>

<%--
<form action="show.jsp" method="post" target="_blank">
<FCK:editor id="content" basePath="/FCKWeb /FCKeditor/"
width="700"
height="500"
skinPath="/TestFCKeditor/FCKeditor/editor/skins/silver/"
toolbarSet = "Default"
>
input
</FCK:editor>
<input type="submit" value="Submit">
</form>
--%>
<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 = "/FCKWeb /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">
<%
FCKeditor oFCKeditor ;
oFCKeditor = new FCKeditor( request, "content" ) ;
oFCKeditor.setBasePath( "/FCKWeb /FCKeditor/" ) ;//注意基本路径设置正确
oFCKeditor.setValue( "input" );
out.println( oFCKeditor.create() ) ;
%>
<br>
<input type="submit" value="Submit">
</form>
--%>

添加文件/TestFCKeditor/show.jsp:
<%
String content = request.getParameter("content");
out.print(content);
out.println(request.getParameter("title"));
%>
<!--表单中的input的name可以等于这里request.getParameter("parameter") 中的parameter参数。可以通过out.println输出
<FCK:editor id="content".....>FCK中的id相当于input的name
-->

11.FCKeditor编辑器文件上传配置
FCKeditor编辑器的配置文件是fckconfig.js,其中有对编辑器各种默认属性的设置。以下是fckeditor与java集成使用 时上传文件的设置(需要注意的是编辑器不会自动创建文件上传的文件夹,需要在项目的根目录中手动添加),将fckeditor.js文件中以下几个属性原 来的值修改为如下设置:

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.ImageUploadURL = FCKConfig.BasePath + 'filemanager/upload/simpleuploader?Type=Image' ;
FCKConfig.FlashUploadURL = FCKConfig.BasePath + 'filemanager/upload/simpleuploader?Type=Flash' ;


至此,即可使用FCKeditor的文件上传功能。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: