我在servlet中要输出一段XML 字符串,但是串中有特殊字符,IE无法解析,FIREFOX是好的
编码是UTF-8特殊字符请看红色的字体
str="<description><![CDATA[opentime?ê[0,299]]]></description>"response.setContentType("text/xml;charset=utf-8");
PrintWriter out = response.getWriter();
out.print(str);
out.flush();
out.close();我不知道特殊字符是什么编码的,因为是别人的数据,请问各位如何想办法把这些字符替代掉.写了下面一个函数,但没起什么作用public static final String escapeHTMLTag(String input) {
input = input.trim().replaceAll("[\\x00-\\x08]", "");
input = input.trim().replaceAll("[\\x0b-\\x0c]", "");
input = input.trim().replaceAll("[\\x0e-\\x1f]", "");
return input;
}
编码是UTF-8特殊字符请看红色的字体
str="<description><![CDATA[opentime?ê[0,299]]]></description>"response.setContentType("text/xml;charset=utf-8");
PrintWriter out = response.getWriter();
out.print(str);
out.flush();
out.close();我不知道特殊字符是什么编码的,因为是别人的数据,请问各位如何想办法把这些字符替代掉.写了下面一个函数,但没起什么作用public static final String escapeHTMLTag(String input) {
input = input.trim().replaceAll("[\\x00-\\x08]", "");
input = input.trim().replaceAll("[\\x0b-\\x0c]", "");
input = input.trim().replaceAll("[\\x0e-\\x1f]", "");
return input;
}
已经解决,是有不可显示的ASII 码
public static final String escapeHTMLTag(String input) {
if (input == null) {
input = "";
return input;
}
input = input.trim().replaceAll("[^\\x00-\\x7F]", "");
return input;
}