SSH2 struts2 FCKeditor在线编辑器实现


Ø        在线编辑器建议使用开源的FCKeditor,FCKeditor官方网站下载地址http://sourceforge.net/projects/fckeditor/files/
 
Ø        需要下载的是两个文件夹:FCKeditor_2.6.6及fckeditor-java-2.4-bin。(此非最新版本版本)前者是解压开后即fckeditor在线编辑器,后者为fckeditor应用在java上的核心包。
 
Ø        接下来开始安装fckeditor,解压FCKeditor_2.6.6后得到fckeditor文件夹。将该文件夹复制到项目的webroot目录下。
 
Ø        然后通过在页面中调用的方式实现fckeditor的使用。具体的调用方法有两种:一、通过javascript调用(推荐)。首先在新建的jsp页面的开头部分声明引入js标签
 
<%String contextPath=request.getContextPath(); %>
 
<script type="text/javascript" src="<%=contextPath %>/fckeditor/fckeditor.js"></script>
 
以上的contextPath是为了解决相对路径的问题,即站点的根路径webroot
 
接下来在body部分应用script代码。例如:
 
  <s:form name="postform" action="saveDrafts.action" method="post">
 
  <table  width="100%">
 
  <s:textfield name="personal_Notes.Title" label="题目(非空)"/>
 
  <s:textarea name="personal_Notes.Neirong" rows="19" cols="97" label="内容"></s:textarea>
 
  <s:select  name="personal_Notes.ShareType" label="权限" list="#{'2':'仅自己可见','1':'公开'}"/>
 
  <script type="text/javascript">
 
          var oFCKeditor=new FCKeditor("personal_Notes.Neirong");
 
          oFCKeditor.BasePath= "<%=contextPath %>/fckeditor/";
 
          oFCKeditor.Height=300;
 
          oFCKeditor.ToolbarSet="itcastbbs";
 
          oFCKeditor.ReplaceTextarea();
 
  </script>
 
  <s:submit value="存草稿" method="savePersonal_Notes2"/>
 
  <s:submit value="发表笔记" method="savePersonal_Notes"/>
 
  </table>
 
  </s:form>
 
在以上的打代码中,通过script引用,新建一个fckeditor对象,并将它的内容赋值给textarea传入到数据库,注意,textarea的名字和fckeditor的对象的名字必须相同。oFCKeditor.BasePath即fckeditor文件夹里面被调用内容的路径。ToolbarSet属性的值为工具栏的名字,可以自己新建一个工具栏调用。
  • 1
  • 2
  • 下一页

相关内容