HTML 转义字符对应表

时间:2023-03-08 18:07:02
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( * length);
for( int i =; 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) %>