IE 下的错误 : An invalid character was found in text content

wbx_1978 2009-05-27 05:02:44
我在Java中写了个servlet,主要是接受ajax传来的值,并且返回XML字符串,

但是同样的条件,在FIREFOX下能在浏览器里正常显示并返回给客户端,

IE下不能在浏览器中显示,也就没办法返回给客户端了

An invalid character was found in text content. Error processing resource 'http://localhost:8080//..

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/xml;charset=utf-9");
//试过ISO-8859-1,也不行
PrintWriter out = response.getWriter();
out.print(str);
out.flush();
out.close();
}

请问怎样才能解决IE下的这个问题


...全文
382 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
caogan111 2009-05-31
  • 打赏
  • 举报
回复

它里面有图形化的向导: help conTents-> MyEclipse Learning center->web services development->getting started-> 而且目前用Xfire用的比较多!
网上很多的介绍,我觉得都是从引申出来的,看原创,可以觉得深入一些。
wbx_1978 2009-05-31
  • 打赏
  • 举报
回复
//XML标准规定的无效字节为: /* 0x00 - 0x08 0x0b - 0x0c 0x0e - 0x1f */

still not work

public static final String escapeHTMLTag(String input) {
if (input == null) {
input = "";
return input;
}

input = input.trim().replaceAll("/[\\x00-\\x08]/", "");
input = input.trim().replaceAll("/[\\x0b-\\x0c]/", "");
input = input.trim().replaceAll("/[\\x0e-\\x1f]/", "");
return input;
}
wbx_1978 2009-05-31
  • 打赏
  • 举报
回复
是的,是utf-8,写在着时写错了

仔细查看后发现在字符串中有特殊字符,不可显示,所以IE会解析错误,但FIREFOX就没事,看下面红色的地方

opentime[0,299]


内容是从数据库中读出来的,请问各位如何才能把这种字符代替掉

yangkangoo12 2009-05-31
  • 打赏
  • 举报
回复
response.setContentType("text/xml;charset=utf-9");
这里应该是utf-8吧
wbx_1978 2009-05-31
  • 打赏
  • 举报
回复
三楼回答挺深奥的,不太理解

现在看来是在字符串里有特殊字符
out.print(str);
jinxfei 2009-05-30
  • 打赏
  • 举报
回复
utf-9?

笔误吧
masse 2009-05-30
  • 打赏
  • 举报
回复
首先,你的servlet输出的编码也要是utf8,

比如你输出编码是gbk,但是你指定了content-type为utf8,好像也是没有用的。

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧