javascript 错误“缺少十六进制数字”的处理
2008-11-24 13:12:00原因:JS提交数据时出现特殊符号"",javascript中""是个特殊的字符,在很多场合需要转换。
参考:
例子程序:
*Encode for HTML.
*/
public static String htmlEncoder(Stringstr)
{
if(str==null|| str.equals(""))
return"";
Stringres_str;
res_str=strReplace(str,"&","&");
res_str=strReplace(str,""," ");
res_str=strReplace(str,"<","<");
res_str=strReplace(str,">","&rt;");
res_str=strReplace(str,""",""");
res_str=strReplace(str,"'","'");
returnres_str;
}
/** *//**
*Encode for HTML-Text.
*/
public static String htmlTextEncoder(Stringstr)
{
if(str==null|| str.equals(""))
return"";
Stringres_str;
res_str=strReplace(str,"&","&");
res_str=strReplace(str,"<","<");
res_str=strReplace(str,">","&rt;");
res_str=strReplace(str,""",""");
res_str=strReplace(str,"'","'");
res_str=strReplace(str,""," ");
res_str=strReplace(str,"rn","<br/>");
res_str=strReplace(str,"r","<br/>");
res_str=strReplace(str,"n","<br/>");
returnres_str;
}
/** *//**
*Encode for URL.
*/
public static String urlEncoder(String str){
returnjava.net.URLEncoder.encode(str) ;
}
/** *//**
*Encode for XML.
*/
public static String xmlEncoder(String str)
{
if(str==null|| str.equals(""))
return"";
Stringres_str;
res_str=strReplace(str,"&","&");
res_str=strReplace(res_str,"<","<");
res_str=strReplace(res_str,">",">");
res_str=strReplace(res_str,""",""");
res_str=strReplace(res_str,"'","´");
returnres_str;
}
/** *//**
*Encode for SQL.
*/
public static String sqlEncoder(String str)
{
if(str==null|| str.equals(""))
return"";
Stringres_str;
res_str=strReplace(str,"'","''");
returnres_str;
}
/** *//**
*Encode for Javascript.
*/
public static String jsEncoder(String str)
{
if(str==null|| str.equals(""))
return"";
Stringres_str;
res_str=strReplace(str,"'","'");
res_str=strReplace(str,""",""");
res_str=strReplace(str,"rn","");
res_str=strReplace(str,"n","");
res_str=strReplace(str,"r","");
returnres_str;
}
html=html+replace(table_list(fileExt,path,2),"","/")+""""