关于FCKeditor,急啊~~~~~~~~~~~~~~~~~~~

全能码农-ss 2010-01-21 06:52:54
我在一个servlet中new了一个FCKeditor ,然后从一个rtf中读取,

(之后输出到控制台是有样式的,标题1,标题2之类的都有),

然后把读取到的字符串serValue进FCKeditor,在页面上请求这个Servlet,

得到的的FCKeditor中文本就没样式了,怎么让它保留样式显示啊?

代码如下:



response.setContentType("text/html");
response.setCharacterEncoding("utf-8");
FCKeditor editor = new FCKeditor(request,"editor1"); //new 一个FCKeditor
FileInputStream in = new FileInputStream("d:/1.rtf"); //读取rtf文档的流
DefaultStyledDocument dsd = new DefaultStyledDocument ();
RTFEditorKit rtf = new RTFEditorKit();
String temp = new String();
try {
rtf.read(in, dsd, 0);
temp = new String(dsd.getText(0, dsd.getLength()).getBytes("ISO8859_1"));
//这样读出之后就有格式了
} catch (BadLocationException e) {
e.printStackTrace();
}
editor.setValue(temp);//把读到的字符串放到FCKeditor 中
in.close();
response.getWriter().println(editor); //吧FCKeditor 输出

...全文
162 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
全能码农-ss 2010-01-26
  • 打赏
  • 举报
回复
很好,结贴给分
junjia 2010-01-26
  • 打赏
  • 举报
回复
直接在页面里直接调用啊
yuzhonglian2004 2010-01-26
  • 打赏
  • 举报
回复
up
xuexijava 2010-01-22
  • 打赏
  • 举报
回复
1、在你页面上引入fckeditor.js
<script type="text/javascript" src="fckeditor/fckeditor.js"></script>
2、加入段Js代码
<script type="text/javascript">
window.onload=function(){
var fc=new FCKeditor("aa"); //这个地方的参数与你的文本域的name值对应
// BasePath必须以斜线结尾,以斜线开始代表当前工程
fc.BasePath="fckeditor/";
fc.Width="50%";
fc.Height="400";
fc.ToolbarSet="Basic"; //设置只显示基本工具栏
fc.ReplaceTextarea();
}
3、你的表单中加入一个文本域,指定它的name与你New的那个FCKeditor参数对就
<textarea name="aa"></textarea>
4、在你的Servlet中直接从request中取文本域的值即可,如果你没有代码过滤的话可以存入格式
楼主可以这样试试
楼下高手继续。。。。。。。。。
  • 打赏
  • 举报
回复
干嘛在servlet里new去页面new去,把value放进去。
fengzhishang55 2010-01-22
  • 打赏
  • 举报
回复
js感觉很好的技术,那位大侠给点好的学习指导!!!
SambaGao 2010-01-22
  • 打赏
  • 举报
回复
可能是在输出到页面上是出来的乱码。所以样式就没了。
你试试英文可以吗?
fengshiyan1943 2010-01-22
  • 打赏
  • 举报
回复
路过~~~~~~~~~~~~~~~~~
「已注销」 2010-01-22
  • 打赏
  • 举报
回复
jf
owen_008 2010-01-22
  • 打赏
  • 举报
回复

给楼主顶一个
zl3450341 2010-01-22
  • 打赏
  • 举报
回复
ckeditor 主页 
http://ckeditor.com/
ckeditor 文档
http://docs.cksource.com/CKEditor_3.x/Developers_Guide/Output_Formatting
crazylaa 2010-01-22
  • 打赏
  • 举报
回复
建议在页面直接写了。
ckeditor 主页
http://ckeditor.com/
ckeditor 文档
http://docs.cksource.com/CKEditor_3.x/Developers_Guide/Output_Formatting
Marty束 2010-01-22
  • 打赏
  • 举报
回复
我也在用fck。
具体的是引入 fck的js文件。在jsp页面中直接调用。
不要在servlet里面写了
另外注意下在jsp页面
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
红色部分要注意,dtd可能不支持你用的fck版本,建议去掉
ComputerHeart 2010-01-22
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 xuexijava 的回复:]
1、在你页面上引入fckeditor.js
<script type="text/javascript" src="fckeditor/fckeditor.js"> </script>
2、加入段Js代码
<script type="text/javascript">
      window.onload=function(){
        var fc=new FCKeditor("aa"); //这个地方的参数与你的文本域的name值对应     
          // BasePath必须以斜线结尾,以斜线开始代表当前工程
          fc.BasePath="fckeditor/";
          fc.Width="50%";
          fc.Height="400";
          fc.ToolbarSet="Basic";  //设置只显示基本工具栏
          fc.ReplaceTextarea();
      }
3、你的表单中加入一个文本域,指定它的name与你New的那个FCKeditor参数对就
<textarea name="aa"> </textarea>
4、在你的Servlet中直接从request中取文本域的值即可,如果你没有代码过滤的话可以存入格式
楼主可以这样试试
[/Quote]
赞成Lz使用这一个!
爻爻燯 2010-01-22
  • 打赏
  • 举报
回复
fckeditor没必要在java类中new出来的,只需要在页面用js new就行了...
luohaobubu 2010-01-22
  • 打赏
  • 举报
回复
字符集的问题
crazy915 2010-01-21
  • 打赏
  • 举报
回复
建议先去看手册吧。

找一下FCKeditor的API。。
全能码农-ss 2010-01-21
  • 打赏
  • 举报
回复
自己顶啊~~~~~~~~~~~

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧