我在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下的这个问题

解决方案 »

  1.   

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

  2.   


    它里面有图形化的向导: help conTents-> MyEclipse Learning center->web services development->getting started-> 而且目前用Xfire用的比较多! 
    网上很多的介绍,我觉得都是从引申出来的,看原创,可以觉得深入一些。
      

  3.   

    三楼回答挺深奥的,不太理解现在看来是在字符串里有特殊字符
    out.print(str); 
      

  4.   

    response.setContentType("text/xml;charset=utf-9"); 
    这里应该是utf-8吧
      

  5.   

    是的,是utf-8,写在着时写错了仔细查看后发现在字符串中有特殊字符,不可显示,所以IE会解析错误,但FIREFOX就没事,看下面红色的地方opentime[0,299]
    内容是从数据库中读出来的,请问各位如何才能把这种字符代替掉
      

  6.   

       //XML标准规定的无效字节为:   /*   0x00 - 0x08   0x0b - 0x0c   0x0e - 0x1f   */still not workpublic 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;
        }