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 梓枫 阅读(1957) 评论(0)  编辑  收藏 所属分类: html

只有注册用户登录后才能发表评论。


网站导航: