栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

htmlentities在JSP中是否等效?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

htmlentities在JSP中是否等效?

public static String stringToHTMLString(String string) {    StringBuffer sb = new StringBuffer(string.length());    // true if last char was blank    boolean lastWasBlankChar = false;    int len = string.length();    char c;    for (int i = 0; i < len; i++)        {        c = string.charAt(i);        if (c == ' ') { // blank gets extra work, // this solves the problem you get if you replace all // blanks with &nbsp;, if you do that you loss  // word breaking if (lastWasBlankChar) {     lastWasBlankChar = false;     sb.append("&nbsp;");     } else {     lastWasBlankChar = true;     sb.append(' ');     } }        else { lastWasBlankChar = false; // // HTML Special Chars if (c == '"')     sb.append("&quot;"); else if (c == '&')     sb.append("&amp;"); else if (c == '<')     sb.append("&lt;"); else if (c == '>')     sb.append("&gt;"); else if (c == 'n')     // Handle newline     sb.append("&lt;br/&gt;"); else {     int ci = 0xffff & c;     if (ci < 160 )         // nothing special only 7 Bit         sb.append(c);     else {         // Not 7 Bit use the unipre system         sb.append("&#");         sb.append(new Integer(ci).toString());         sb.append(';');         }     } }        }    return sb.toString();}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/417329.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号