Function xuankong(str)
Dim result
Dim j
j=len(str)
result=""
Dim i
For i=1 To j
Select Case mid(str,i,1)
Case """"
result=result+"">""
Case chr(34)
result=result+""
Case ""&""
result=result+""&""'以上代???一些html??
Case chr(255)'防止特殊空格
result=result
Case chr(13)'防止回?符
result=result+""
Case chr(32)'防止?行符
result=result+""
Case Else
result=result+mid(str,i,1)
End Select
Next
xuankong=result
End Function
這個是ASP實現,思路可用於JSP
public String filterHtml(String value){
value=value.replaceAll("&","&");
value=value.replaceAll("",">");
value=value.replaceAll(" ","");
value=value.replaceAll("'","'");
value=value.replaceAll("/"",""");
value=value.replaceAll("/n","
"); } 在頁面中 string temp=filterHtml(request.getParameter(temp));
"); } 在頁面中 string temp=filterHtml(request.getParameter(temp));