使用可视化编辑器ewebedit(纯javascript)的编辑时的问题
我在jsp的代码里使用了ewebedit编辑器精简版(纯javascript)
在添加页正常使用
但是在修改页面就常常出错
asp里有server.htmlencode这样的方法来阻止代码在编辑器里执行,
jsp里没有这样的函数
我试了去处和转换数据库字段的东西
添加了htmlencode函数但还是不行
这种问题在jsp里怎么解决?
------解决方案--------------------public final class HtmlFunction{
/**
*编码html字符
*/
public static String htmlEncode(String str){
String txt = str;
txt = txt.replaceAll( "& ", "& ");
txt = txt.replaceAll( "& ", "& ");
txt = txt.replaceAll( "" ", "" ");
txt = txt.replaceAll( "/ ", "" ");
txt = txt.replaceAll( "&lt; ", "< ");
txt = txt.replaceAll( " < ", "< ");
txt = txt.replaceAll( "&gt; ", "> ");
txt = txt.replaceAll( "> ", "> ");
txt = txt.replaceAll( "&nbsp; ", " ");
txt = txt.replaceAll( " ", " ");
return txt;
}
/**
*反编码html字符
*/
public static String unHtmlEncode(String str){
String txt = str;
txt = txt.replaceAll( "& ", "& ");
txt = txt.replaceAll( "" ", "/ ");
txt = txt.replaceAll( "< ", " < ");
txt = txt.replaceAll( "> ", "> ");
txt = txt.replaceAll( " ", " ");
return txt;
}
/**
*去除str的HTML格式
*/
public static String clearHtml(String str){
//将regex编译到模式,不区分大小写
Pattern p = Pattern.compile( " <[^> ]+> | </[^> ]+> ",Pattern.CASE_INSENSITIVE );
Matcher m = p.matcher(str);
return m.replaceAll( " ");
}
}
------解决方案--------------------无语
运行一下这个HTML
<script>
//write by theForever csdn.net
function ClearHtmlCode(txt){
txt=txt.replace(/&/g, "& ");
txt=txt.replace(/ </g, "< ");
txt=txt.replace(/> /g, "> ");
return txt;
}
</script>
<input type= 'button ' onclick= "txt.value=ClearHtmlCode(txt.value); " value= '替换后面文本HTML标记 '>
<input id=txt type= 'text ' value= ' <html> 去掉<> sksj <nikb > '>