复制代码 代码如下:
/**
* html代码输入验证转换
* @param str
* @return
*/
public string htmlfilter(string str){
//转意&
str = str.replaceall("&", "&");
//转意<
str = str.replaceall("<", "<");
//转意>
str = str.replaceall(">", ">");
//转意空格,
//注意:空格使用" "会导致xml解析出错!,这里只能使用" "
str = str.replaceall(" ", " ");
//转意单引号
str = str.replaceall("'", "'");
//转意双引号
str = str.replaceall(""", """);
//转意换行
str = str.replaceall("\n", "<br>");
return str;
}
//本方法用于在servlet生成xml代码中再次转意,主要是把<br>转换为正常显示
public string htmlfilter2(string str){
//转意<
str = str.replaceall("<", "<");
//转意>
str = str.replaceall(">", ">");
return str;
}