首页  >  文章  >  web前端  >  转义HTML字符_html/css_WEB-ITnose

转义HTML字符_html/css_WEB-ITnose

WBOY
WBOY原创
2016-06-21 09:16:061019浏览

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());    }}




声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn