转义HTML字符_html/css_WEB-ITnose

WBOY
Release: 2016-06-21 09:16:06
Original
1021 people have browsed it

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




Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template