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 梓楓 閱讀(1977) 評論(0)  編輯  收藏 所屬分類: html
          主站蜘蛛池模板: 阳曲县| 恩平市| 吉林省| 新巴尔虎右旗| 哈尔滨市| 阿拉善右旗| 株洲县| 浦江县| 北海市| 龙山县| 富阳市| 原平市| 平凉市| 遵义县| 东台市| 偏关县| 柳江县| 运城市| 惠水县| 隆安县| 和平区| 茌平县| 马尔康县| 鄂托克前旗| 洛扎县| 沙河市| 五大连池市| 水城县| 安龙县| 江安县| 兰州市| 扶风县| 波密县| 施秉县| 余庆县| 南雄市| 抚松县| 七台河市| 大同县| 盐池县| 罗江县|