HTML 转义字符对应表

 

<%@ tag language="java"   pageEncoding="UTF-8"  %>
<%@ attribute name="input"  required="true"  %>
<%!
    private String encodedHtmlTag(String tag){
    if ( tag == null) return null;
    int length = tag.length();
    StringBuilder encodedTag = new StringBuilder(2 * length);
    for( int i =0; i < length; i++)
    {
        char c = tag.charAt(i);
        if( c == '<')
            encodedTag.append("&lt;");
        else if ( c == '>')
            encodedTag.append("&gt;");
        else if ( c == '&')
            encodedTag.append("&amp;");
        else if ( c == '"')
            encodedTag.append("&qout");
        else if ( c == ' ')
            encodedTag.append("&nbsp;");
        else
            encodedTag.append(c);
    }
    return encodedTag.toString();
}
%>
<%=encodedHtmlTag(input) %>

 

posted @ 2019-04-14 16:56  江期玉  阅读(541)  评论(0编辑  收藏  举报