fckeditor 读数据库数据显示不正常(转)

fckeditor免费的版本,存在很多问题.比如你可以插一个图片,或是改变文本的格式.但是当你单击提交保存在数据库中了.它将按源代码中的格式保存并不做相关的处理.这样也就造成了,当你再次想修改上次的内容时,在fckeditor无法显示了.
 

<form action="ActionServlet?method=modifyContactUs&action=SiteConfigAction&page=admin/manager_config/modify_contact_us.jsp" method="post">
<table width="80%" align="center">
<tr>
<td colspan="2">联系我们</td>
<td>&nbsp;
</td>
</tr>
<tr>
<td colspan="2"><br><script type="text/javascript">
var oFCKeditor =new FCKeditor('contact_us');
oFCKeditor.BasePath
="fckeditor/";
oFCKeditor.Width
="90%";
oFCKeditor.Height
="600" ;
oFCKeditor.Value
="<%=siteConfig.getContactUs() %> " ; //问题在这
oFCKeditor.ToolbarSet="fvedu";
oFCKeditor.Config[
"CustomConfigurationsPath"] ="/pvedu/js/admin_fckeditor.js" ; //这里是我的fckeditor配置文件
oFCKeditor.Create();
</script>
<br></td>

</tr>

<tr>
<td>
<input type="submit" name="submit" value="提交">
</td>
</tr>
</table>
</form>

 问题在oFCKeditor.Value="";它这里是用了""来显示出内容.但是如果你从数据库中读出的内容本身有"号时,就会造成不正常
的显示.比如你的value中的内容是<img src="**">是就会变成oFCKeditor.Value="<img src="**">";这样就给value赋了不正常的内容了.
还有是一种情况当你输入如下内容:
第一行内容
第二行内容
当你输入上面的两行内容时,本身代码是没有什么问题的,fckeditor将会把它变成
第一行内容<br>
第二行内容
但是这里有个软回车,当你单击保存在数据库时,它会又出现了问题,此时
OfCKeditor.Value="第一行内容<br>
第二行内容";
发现了吧,它的""双引号不在一行,问题就暴露无遗出来了fckeditor又不认识这些东西.所以可编辑区域它又会不显示.
解决方法
在读数据库的数据时,你先做些预处理,可以给你将要处理的字符串调用如下方法
 

publicstatic String repalceDoubleQuotationAndSoftEnter(String doubleStr)
{
String resultStr
=null ;

if(null!=doubleStr)
{
resultStr
= doubleStr.replace("\"", "'"); //替换掉双引号为单引号
resultStr = resultStr.replace("\r\n", ""); //将软件回车替换为空
}

return resultStr ;
}

这样就可以防止fckeditor不显示了.

posted @ 2013-06-08 13:14  旭♥燕  阅读(455)  评论(0编辑  收藏  举报