posts - 75,comments - 83,trackbacks - 0

           

          問題:
          我是打算使用上面的語句把數(shù)據(jù)庫的連接字符串寫入上一級網(wǎng)頁的connstr文本框中,但是在執(zhí)行時ie總報告“缺少十六進(jìn)制數(shù)字”。
          代碼如下:
          a
          ="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=E:\網(wǎng)站設(shè)計\dianming\upload\student.mdb;"
          Response.Write(
          "<script>")
              html
          ="parent.document.getElementById(""connstr"").value="""+a+""""
              Response.Write(html
          +";")
          Response.Write(
          "</script>")
          問題分析:
          到底是怎么回事呢?經(jīng)過試驗(yàn)發(fā)現(xiàn),問題出在字符串a(chǎn)中的 “\” 上,    原來javascript中“\”是個特殊的字符,在很多場合需要轉(zhuǎn)換,為此我使用“
          /“臨時替代”\“一下,在使用到此字符串的時候再轉(zhuǎn)換回來就可以了。
          代碼改寫如下:
          a
          ="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=E:\網(wǎng)站設(shè)計\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 梓楓 閱讀(1976) 評論(0)  編輯  收藏 所屬分類: html
          主站蜘蛛池模板: 南阳市| 石首市| 临夏市| 新余市| 三台县| 五台县| 高邑县| 图片| 青铜峡市| 克拉玛依市| 周口市| 翁源县| 福建省| 麻江县| 永昌县| 海城市| 汉源县| 汪清县| 广平县| 绥中县| 西乌| 中山市| 亚东县| 洛川县| 奉新县| 富民县| 石泉县| 天等县| 湘乡市| 财经| 东乌| 阿拉尔市| 合水县| 平凉市| 永吉县| 潞西市| 临湘市| 宝坻区| 法库县| 乡城县| 乐昌市|