Problem:
I plan to use the preceding statement to write the connection string of the database to the connstr text box on the upper-level webpage. However, during execution, ie reports that the hexadecimal number is missing ".
The Code is as follows:
A = "provider = Microsoft. Jet. oledb.4.0; Data Source = E:/Website Design/Dianming/upload/student. mdb ;"
Response. Write ("<SCRIPT> ")
Html = "parent.doc ument. getelementbyid (" "connstr" "). value =" "+ A + """"
Response. Write (HTML + ";")
Response. Write ("</SCRIPT> ")
Problem Analysis:
What is going on? It is found that the problem lies in the "/" in the string a. In JavaScript, "/" is a special character and needs to be converted in many cases, for this reason, I will use "/" temporary substitution "/" and convert it back when using this string.
The code is rewritten as follows:
A = "provider = Microsoft. Jet. oledb.4.0; Data Source = E:/Website Design/Dianming/upload/student. mdb ;"
Html = HTML + Replace (a, "/", "/") + """"
Response. Write ("<SCRIPT> ")
Html = "parent.doc ument. getelementbyid (" "connstr" "). value =" "+ A + """"
Response. Write (HTML + ";")
Response. Write ("</SCRIPT> ")
Refer:
Example program:
* 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;
}
Html = HTML + Replace (table_list (fileext, path, 2), "/", "/") + """"