使用可视化编辑器ewebedit(纯javascript)的编辑时的问题 我在jsp的代码里使用了ewebedit编辑器精简版(纯javascript)在添加页正常使用但是在修改页面就常常出错asp里有server.htmlencode这样的方法来阻止代码在编辑器里执行,jsp里没有这样的函数我试了去处和转换数据库字段的东西添加了htmlencode函数但还是不行这种问题在jsp里怎么解决? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 好像我以前用过一个rte就是自己写了一个encode函数把特殊标记驱除的 public final class HtmlFunction{ /** *编码html字符 */ public static String htmlEncode(String str){ String txt = str; txt = txt.replaceAll("&","&"); txt = txt.replaceAll("&amp;","&"); txt = txt.replaceAll("&quot;","""); 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(""); }} 楼上的swoky兄弟我是asp程序员,现在还不太会jsp,那个用类的代码要怎么用啊? 无语运行一下这个HTML<script>//write by theForever csdn.netfunction 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 >'> 在webedit的官方网站找到如下代码,问题解决!http://ewebeditor.webasp.net/manual/#_Toc160644280<%!static String htmlEncode(int i){ if (i=='&') return "&"; else if (i=='<') return "<"; else if (i=='>') return ">"; else if (i=='"') return """; else return ""+(char)i;} static String htmlEncode(String st){ StringBuffer buf = new StringBuffer(); for (int i = 0;i<st.length();i++){ buf.append(htmlEncode(st.charAt(i))); } return buf.toString();}%><textarea name="content1" style="display:none"><%=htmlEncode(str)%></textarea><IFRAME ID="eWebEditor1" src="../ewebeditor.htm?id=content1&style=coolblue" frameborder="0" scrolling="no" width="550" height="350"></IFRAME> 碧海晴天的那个要是onload时执行可能可以吧!,谢谢! 这段代码错在哪? HTML标签问题 为何在myeclipse6.5中的xml文件中会出现这么多警告 编码转换,第一来,多多指教 jbuilderX 写jsp时怎么连接sql2005(sql2005在服务器上) 有人调试过"天乙社区7.1.1"吗? 请问哪里可以下载JBUILDX啊? 用tomcat5.0.19,javabeans的class文件应放在哪里? 怎样把路径地址解析成一网址?(在Websphere中) 关于ejb的远程调用问题 最近无事 帮人做javascript , ajax 类的东西 免费 apache+tomcat实现url rewrite遇到的问题,急求高手解答
/**
*编码html字符
*/
public static String htmlEncode(String str){
String txt = str;
txt = txt.replaceAll("&","&");
txt = txt.replaceAll("&amp;","&");
txt = txt.replaceAll("&quot;",""");
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("");
}
}
我是asp程序员,现在还不太会jsp,那个用类的代码要怎么用啊?
//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 >'>
http://ewebeditor.webasp.net/manual/#_Toc160644280
<%!static String htmlEncode(int i){ if (i=='&') return "&"; else if (i=='<') return "<"; else if (i=='>') return ">"; else if (i=='"') return """; else return ""+(char)i;} static String htmlEncode(String st){ StringBuffer buf = new StringBuffer(); for (int i = 0;i<st.length();i++){ buf.append(htmlEncode(st.charAt(i))); } return buf.toString();}%>
<textarea name="content1" style="display:none"><%=htmlEncode(str)%></textarea><IFRAME ID="eWebEditor1" src="../ewebeditor.htm?id=content1&style=coolblue" frameborder="0" scrolling="no" width="550" height="350"></IFRAME>