过滤public static String filter(String value) {
if (value == null)
return (null);
StringBuffer result = new StringBuffer();
for (int i = 0; i < value.length(); i++) {
char ch = value.charAt(i);
if (ch == '
result.append("<");
else if (ch == '>')
result.append(">");
else if (ch == '&')
result.append("&");
else if (ch == '"')
result.append(""");
else if (ch == '\r')
result.append("
");
else if (ch == '\n') {
if (i > 0 && value.charAt(i - 1) == '\r') {
} else {
result.append("
");
}
} else if (ch == '\t')
result.append("  ");
else if (ch == ' ')
result.append(" ");
else
result.append(ch);
}
return (result.toString());
}
2008年9月05日 17:50