struts2 怎样获得FCKEditor的内容啊?
比如要是普通的表单,在Action中定义一个属性和表单的name一样就行了,但是FCKEditor就不行啊!

解决方案 »

  1.   

    看看我的blog就知道了
    http://blog.csdn.net/lihan6415151528/archive/2008/10/18/3094793.aspx
      

  2.   

    同样的在Action中定义一个属性和表单的name一样就行了
    然后导入fckeditor.js
    在页面上添加JS:
    <textarea id="content" name="content" style="WIDTH: 100%; HEIGHT: 400px">input</textarea>
    <script type="text/javascript">
     var oFCKeditor = new FCKeditor('content') ; //content为你在action中定义的属性
     oFCKeditor.Height = 400;            //高宽自己定义 但不会超过css的样式
     oFCKeditor.ToolbarSet = "Default" ; //FCK中的选项样式 这里使用默认 可参考源码里的定义自己修改
     oFCKeditor.ReplaceTextarea();
    </script>这就是最简单的使用
      

  3.   

    FCKEditor在提交时就是一个普通的http post提交,只要在Struts 2的Action类或模型类中加入与FCKEditor编辑器名相同的属性即可。属性类型是String类型。var oFCKeditor = new FCKeditor('content') ;属性名就是FCKEditor框架方法的参数值。
      

  4.   

    请看下面的HTML的代码,基本上你按照下面的配置就可以在Struts使用Fck了。其实Fck和Struts是没有什么关联的。
    1. fck放在WebRoot下面,使得你的Web应用程序能访问得到
    2. 加入一个textarea,
    3. 使用onload事件把textarea替换成fckeditor
    4. submit的时候你在后台代码中要定义一个get方法和textarea中的name要匹配
       如:<textarea rows="5" cols="35" name="description"></textarea> 的name是description
       那必须要有个getDescription()的方法。
    <!--fck这个文件夹要放在WebRoot目录下面-->
    <script type="text/javascript" src="fck/fckeditor.js"></script>
    <!--Struts的表单-->
    <s:form action="myAction" name="myForm">
    <textarea rows="5" cols="35" name="description"></textarea>
    <input type="submit" value="提交" />
    </s:form>
    <script type="text/javascript">
    //初始化的一个onload事件,用于把名字为description的textarea html标签替换成FCK的Editor
    function init() {
         var bodyFCKeditor = new FCKeditor('description');
         bodyFCKeditor.BasePath = 'fck/';
         bodyFCKeditor.ToolbarSet = 'Default';
         bodyFCKeditor.Width = '95%';
         bodyFCKeditor.Height = '400';
         bodyFCKeditor.Value = '';
         bodyFCKeditor.ReplaceTextarea();
    }//onload事件
    window.onload = init;
    </script>