1、直接儲存,然後當從資料庫中取出來時用過濾方法過濾一遍再送回頁面即可,給一段代碼,看了就明白了,可以自己擴充
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("<BR>");
else if (ch == '\n') {
if (i > 0 && value.charAt(i - 1) == '\r') {