可以过滤掉 例如把 “<” 转换为 &lt;  等等.....

解决方案 »

  1.   

    用replace把"<"">"替换成"&lt;""&gt;"
      

  2.   

    这不是什么BUG吧.
    还有更多的呢
    1,字符串输出至HTML.
    2,输出至URL
    3,输出至javascript等脚本
    4,输出至sql
    ...
      

  3.   

    <%Function fn_chk_to_html(Str)
     If Isnull(Str) or Str = "" or (len(Str)<0) Then
      fn_chk_to_html = ""
      Exit Function 
     End If
     Str = trim(Str)
     Str = Replace(Str, Chr(0), "",1,-1,1)
     Str = Replace(Str, """", "&quot;",1,-1,1)
     Str = Replace(Str, "'", "&#039;",1,-1,1)
     Str = Replace(Str, "<","&lt;",1,-1,1)
     Str = Replace(Str, ">","&gt;",1,-1,1)
     Str = Replace(Str, vbCrlf, "<br>",1,-1,1) 
     fn_chk_to_html = Str
    End Function
    %>
    <%Function fn_chk_to_script(Str)
     If Isnull(Str) or Str = "" or (len(Str)<0) Then
      fn_chk_to_script = ""
      Exit Function 
     End If
     Str = trim(Str)
     Str = Replace(Str, "\", "\\",1,-1,1)
     Str = Replace(Str, """", "\""",1,-1,1)
     Str = Replace(Str, "'", "\'",1,-1,1)
     Str = Replace(Str, chr(13), "\n",1,-1,1)
     fn_chk_to_script = Str
    End Function
    %>
    <%Function fn_chk_to_sql_(Str)
     If Isnull(Str) or Str = "" or (len(Str)<0) Then
      fn_chk_to_sql_ = ""
      Exit Function 
     End If
     Str = trim(Str)
     Str = Replace(Str, "'", "''",1,-1,1)
     fn_chk_to_sql_ = Str
    End Function
    %><%Function fn_chk_to_sql_go(Str)
     If Isnull(Str) or Str = "" or (len(Str)<0) Then
      fn_chk_to_sql_go = ""
      Exit Function 
     End If
     Str = trim(Str)
     Str = Replace(Str, Chr(0), "",1,-1,1)
     Str = Replace(Str, """", "&quot;",1,-1,1)
     Str = Replace(Str, "'", "&#039;",1,-1,1)
     Str = Replace(Str, "<","&lt;",1,-1,1)
     Str = Replace(Str, ">","&gt;",1,-1,1) 
     Str = Replace(Str, "[", "&#091;",1,-1,1)
     Str = Replace(Str, "]", "&#093;",1,-1,1)
     Str = Replace(Str, "\", "&#092;",1,-1,1)
     Str = Replace(Str, "*", "&#042;",1,-1,1)
     Str = Replace(Str, "%", "&#037;",1,-1,1)
     Str = Replace(Str, ";", "&#059;",1,-1,1)
     Str = Replace(Str, vbCrlf, "<br>",1,-1,1)
     Str = Replace(Str, "--", "&#045;&#045;")
     fn_chk_to_sql_go = Str
    End Function
    %><%Function fn_chk_to_url(Str)
     If Isnull(Str) or Str = "" or (len(Str)<0) Then
      fn_chk_to_url = ""
      Exit Function 
     End If
     Str = trim(Str)
     Str = server.URLEncode(Str)
     fn_chk_to_url = Str
    End Function
    %>
      

  4.   

    同楼上,来个java版的:
    /*
     * Created by Seamus
     * Updated on 2004-10-21 by JK
     *
     */
    package com.jk.util;public class  CommStr
    {
      /**
      *replace the old string to new string in the given destination string.
      */
      public static java.lang.String strReplace(java.lang.String destStr, java.lang.String oldStr, java.lang.String newStr)
      {
        if(destStr==null)
          return "";
        String tmpStr = destStr;
        int foundPos = tmpStr.indexOf(oldStr);
        while (foundPos>=0)
        {
          tmpStr = tmpStr.substring(0,foundPos) + newStr + tmpStr.substring(foundPos + oldStr.length(),tmpStr.length());
          foundPos = tmpStr.indexOf(oldStr,foundPos+newStr.length());
        }
        return tmpStr;
      }  /**
      *Encode for HTML.
      */
      public static String htmlEncoder(String str)
      {
        if(str==null || str.equals(""))
          return "";
        String res_str;
        res_str=strReplace(str,"&","&amp;");
        res_str=strReplace(str," ","&nbsp;");
        res_str=strReplace(str,"<","&lt;");
        res_str=strReplace(str,">","&rt;");
        res_str=strReplace(str,"\"","&quot;");
        res_str=strReplace(str,"'","&#039;");
        return res_str;
      }  /**
      *Encode for HTML-Text.
      */
      public static String htmlTextEncoder(String str)
      {
        if(str==null || str.equals(""))
          return "";
        String res_str;
        res_str=strReplace(str,"&","&amp;");
        res_str=strReplace(str,"<","&lt;");
        res_str=strReplace(str,">","&rt;");
        res_str=strReplace(str,"\"","&quot;");
        res_str=strReplace(str,"'","&#039;");
        res_str=strReplace(str," ","&nbsp;");
        res_str=strReplace(str,"\r\n","<br>");
        res_str=strReplace(str,"\r","<br>");
        res_str=strReplace(str,"\n","<br>");
        return res_str;
      }  /**
      *Encode for URL.
      */
      public static String urlEncoder(String str) {
        return java.net.URLEncoder.encode(str) ;
      }  /**
      *Encode for XML.
      */
      public static String xmlEncoder(String str)
      {
        if(str==null || str.equals(""))
          return "";
        String res_str;
        res_str=strReplace(str,"&","&amp;");
        res_str=strReplace(res_str,"<","&lt;");
        res_str=strReplace(res_str,">","&gt;");
        res_str=strReplace(res_str,"\"", "&quot;");
        res_str=strReplace(res_str,"\'", "&acute;");
        return res_str;
      }  /**
      *Encode for SQL.
      */
      public static String sqlEncoder(String str)
      {
        if(str==null || str.equals(""))
          return "";
        String res_str;
        res_str=strReplace(str,"'","''");
        return res_str;
      }  /**
      *Encode for Javascript.
      */
      public static String jsEncoder(String str)
      {
        if(str==null || str.equals(""))
          return "";
        String res_str;
        res_str=strReplace(str,"'","\\'");
        res_str=strReplace(str,"\"","\\\"");
        res_str=strReplace(str,"\r\n","\\\n");
        res_str=strReplace(str,"\n","\\\n");
        res_str=strReplace(str,"\r","\\\n");
        return res_str;
      }}
      

  5.   

    记得以前提这个问题的时候,...
    http://community.csdn.net/Expert/topic/4172/4172187.xml?temp=.3651087
    估计.JK_10000(JK)大侠没有看到.要不,我就不用这么辛苦去做那几个函数了.
    呵.