欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  web前端

转义HTML字符_html/css_WEB-ITnose

程序员文章站 2022-05-19 08:17:48
...
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 ':                result.append(">");                break;            case '&':                result.append("&");                break;            case '"':                result.append(""");                break;            default:                result.append(content[i]);            }        }        return (result.toString());    }}
相关标签: 转义HTML字符