首先,处理查询取得要修改的文章内容字符串:
由于,文章中包含了多种标签,因此在页面显示时必须先将字符串中的 引号, 回车, 换行 进行转义,否则会造成编辑器创建失败或者文章内容超出编辑区。
jsp 用此方法转换
<%
Information news = (Information)request.getAttribute("news");
String context = news.getContext();
String tempContext = context.replace("'","/'");
tempContext = context.replaceAll("/r/n","<br>");
%>
转换后,再将值赋给fckeditor
<script type="text/javascript">
var oFCKeditor = new FCKeditor('context');
oFCKeditor.BasePath='resources/fckeditor/';
oFCKeditor.Height='450px';
oFCKeditor.Width='800px';
oFCKeditor.ToolbarSet='DefaultNoForm';
oFCKeditor.Value = ' <%=tempContext%>' ;//默认值
oFCKeditor.Create();
</script>
至此,就能修改之前用 fckeditor 编辑过的内容,而不至于处理乱容时常常导致js错误,或html语法错误。