FCKEditor总结

使用方法
1.将文件复制到WebRoot目录下
<%@ page language="java"  pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>FckEdit</title>	
  </head>
<!--先引入JS文件-->
  <script type="text/javascript" src="./fckeditor/fckeditor.js"></script>
  <script type="text/javascript">
<!--添加事件-->
  		window.onload = function(){  			<!--创建对象,因为javascript是传多少个参数都可以的-->
  			var edit = new FCKeditor('ReplaceText','60%','400','Basic');
<!--设置地址-->
  			edit.BasePath = '/FckEdit/fckeditor/';
<!--调用对象参数,Replace下面的Textarea-->
  			edit.ReplaceTextarea();
  		}
  </script>
  <body>  
    <form action="" method="post" name="fckform" id="fckform" >
  		<script type="text/javascript">
  			var fckedit = new FCKeditor('FCKEditorName','50%','300','Default');
  			fckedit.BasePath = '/FckEdit/fckeditor/';
<!--直接创建-->
  			fckedit.Create();
  		</script>
  		<br/>
  		<textarea name="ReplaceText" rows="5" cols="30">浪花</textarea>
  	</form> 
  </body>
</html>

在服务器端用request.getParameter("name")获得参数
还有一种用JSP标签的方法

过滤Javascript恶意代码
public class StringUtil {
	//查看这个字符串是否为空
	public static boolean validateNull(String args){
		if(args==null||args.length()==0){
			return true;
		}else{
			return false;
		}		
	}
	//查看source是否为空并长度为0,如果成立用target代替
	public static String chanageNull(String source,String target){
		if(source==null||source.length()==0){
			return target;
		}else{
			return source;
		}
	}
	//过滤恶意Javascript代码等信息
	public static String filterHtml(String input){
		if(input==null){
			return null;
		}
		if(input.length()==0){
			return input;
		}
//下面的先后顺序不能乱,因为如果先replaceAll了\n到<br>就没有办法换行了
		input = input.replaceAll("&", "&amp;");
		input = input.replaceAll("<", "&lt;");
		input = input.replaceAll(">", "&gt;");
		input = input.replaceAll(" ", "&nbsp;");
		input = input.replaceAll("'", "&#39;");
		input = input.replaceAll("\"", "&quot;");
		input = input.replaceAll("\n", "<br>");
		return input;
	}
}

你可能感兴趣的:(JavaScript,html,jsp,fckeditor)