转义HTML字符_html/css_WEB-ITnose

WBOY
发布: 2016-06-21 09:16:06
原创
1020 人浏览过

package util;public final class HTMLFilter {    /**     * Filter the specified message string for characters that are sensitive     * in HTML.  This avoids potential attacks caused by including JavaScript     * codes in the request URL that is often reported in error messages.     *     * @param message The message string to be filtered     */    public static String filter(String message) {        if (message == null)            return (null);        char content[] = new char[message.length()];        message.getChars(0, message.length(), content, 0);        StringBuilder result = new StringBuilder(content.length + 50);        for (int i = 0; i < content.length; i++) {            switch (content[i]) {            case '<':                result.append("<");                break;            case '>':                result.append(">");                break;            case '&':                result.append("&");                break;            case '"':                result.append(""");                break;            default:                result.append(content[i]);            }        }        return (result.toString());    }}
登录后复制




相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板