过滤html恶意代码
2016-06-30 15:58
405 查看
/** * 转义HTML特殊字符 */ public static final String trunhtml(String html){ if(html == null) return null; final StringBuilder newhtml = new StringBuilder(""); final char[] chararray = html.toCharArray(); for(char c : chararray){ if(c == '\r') continue; if(c == '&') newhtml.append("&"); else if(c == '#') newhtml.append("#"); else if(c == '*') newhtml.append("*"); else if(c == ':') newhtml.append(":"); else if(c == ';') newhtml.append(";"); else if(c == '<') newhtml.append("<"); else if(c == '>') newhtml.append(">"); else if(c == ' ') newhtml.append(" "); else if(c == '\n') newhtml.append("<br />"); else if(c == '"') newhtml.append("""); else if(c == '\'') newhtml.append("'"); else if(c == '/') newhtml.append("/"); else if(c == '$') newhtml.append("$"); else if(c == '(') newhtml.append("("); else if(c == ')') newhtml.append(")"); else if(c == '{') newhtml.append("{"); else if(c == '}') newhtml.append("}"); else if(c == '*') newhtml.append("*"); else if(c == '%') newhtml.append("%"); else if(c == '+') newhtml.append("+"); else if(c == '-') newhtml.append("-"); else if(c == '~') newhtml.append("~"); else if(c == '\t') newhtml.append(" "); else newhtml.append(c); } return newhtml.toString(); }
相关文章推荐
- EditPlus中的html自动补全
- EditPlus中的html自动补全
- 关于HTML
- Html-知识点总结
- swiper的基础教程(十二)
- html的input标签,设置size后会影响到页面的放大缩小排版
- HTML的基础学习(第1篇)
- swiper的基础教程(十二)
- html进制转换
- HTML学习笔记1.6-高亮文本及组合使用
- HTML新人基础学习1.4—添加常用的标签
- htmlhe和script结合制作简易计算器
- HTML DOCTYPE 的重要性
- 两种方法实现在HTML页面加载完毕后运行
- HTML 文字逐一显示
- html-tab page
- 使用HTML注释判断IE版本
- html中radio值的获取、赋值、注册事件示例详解
- HTML 5 <input> type 属性
- HTML <form> 标签的 action 属性