WEB开发网
开发学院网页设计JavaScript javascript 错误“缺少十六进制数字”的处理 阅读

javascript 错误“缺少十六进制数字”的处理

 2008-10-20 20:00:38 来源:WEB开发网   
核心提示:原因:JS提交数据时出现特殊符号"\",javascript中"\"是个特殊的字符,javascript 错误“缺少十六进制数字”的处理,在很多场合需要转换,参考:例子程序:*Encode for HTML.*/public static String htmlEncoder(S
原因:JS提交数据时出现特殊符号"\",javascript中"\"是个特殊的字符,在很多场合需要转换。
参考:
例子程序:
*Encode for HTML.
*/
public static String htmlEncoder(String str)
{
   if(str==null || str.equals(""))
    return "";
   String res_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,"'","'");
   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,"&","&");
   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,"\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,"&","&");
   res_str=strReplace(res_str,"<","<");
   res_str=strReplace(res_str,">",">");
   res_str=strReplace(res_str,"\"", """);
   res_str=strReplace(res_str,"\'", "´");
   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),"\","/")+""""

Tags:

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接