posts - 75,comments - 83,trackbacks - 0

           

          問題:
          我是打算使用上面的語句把數據庫的連接字符串寫入上一級網頁的connstr文本框中,但是在執行時ie總報告“缺少十六進制數字”。
          代碼如下:
          a
          ="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=E:\網站設計\dianming\upload\student.mdb;"
          Response.Write(
          "<script>")
              html
          ="parent.document.getElementById(""connstr"").value="""+a+""""
              Response.Write(html
          +";")
          Response.Write(
          "</script>")
          問題分析:
          到底是怎么回事呢?經過試驗發現,問題出在字符串a中的 “\” 上,    原來javascript中“\”是個特殊的字符,在很多場合需要轉換,為此我使用“
          /“臨時替代”\“一下,在使用到此字符串的時候再轉換回來就可以了。
          代碼改寫如下:
          a
          ="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=E:\網站設計\dianming\upload\student.mdb;"
          html
          =html+replace(a,"\","/")+""""
          Response.Write(
          "<script>")
              html
          ="parent.document.getElementById(""connstr"").value="""+a+""""
              Response.Write(html
          +";")
          Response.Write(
          "</script>")
          參考:
          例子程序:
          *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,"'","'");
              
          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,"'","'");
              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;
            }

          html
          =html+replace(table_list(fileExt,path,2),"\","/")+""""
          posted on 2008-01-15 16:14 梓楓 閱讀(1980) 評論(0)  編輯  收藏 所屬分類: html
          主站蜘蛛池模板: 周宁县| 奉新县| 正阳县| 凤台县| 来安县| 江口县| 辽中县| 济宁市| 屏山县| 宕昌县| 卓资县| 舞钢市| 东明县| 三门峡市| 定边县| 浑源县| 乌拉特前旗| 元谋县| 来宾市| 英吉沙县| 合水县| 鄱阳县| 绥中县| 贡觉县| 通城县| 闽侯县| 肥乡县| 米脂县| 阿拉善左旗| 寿光市| 泸定县| 宣化县| 遂溪县| 崇信县| 义马市| 万源市| 海南省| 五大连池市| 绵阳市| 屏山县| 砚山县|