servlet接收从前端传来的XML格式的请求,在做处理时出错。前端的jsp采用编码为:
<META http-equiv=Content-Type content="text/html; charset="UTF-8">后台的servlet采用接收编码为:
request.setCharacterEncoding("UTF-8");
出错代码:
try{
System.out.println(xml.toString());
xmlDoc=DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(xml.getBytes()));
}
catch(ParserConfigurationException e){System.out.println(e);}
catch(SAXException e){System.out.println(e);}
catch(Exception e){System.out.println(e);}
服务器控制台显示:
<user><name>李小王</name><psw>123456</psw></user>
java.io.UTFDataFormatException: Invalid byte 1 of 1-byte UTF-8 sequence.应该是编码与getBytes()或ByteArrayInputStream()的双字节与单字节的不一致,请各位帮忙指出如何更进!

解决方案 »

  1.   

    java.io.UTFDataFormatException: Invalid byte 1 of 1-byte UTF-8 sequence.]
    通过editplug之类的打开,另存为 选择utf-8编码  就OK了
      

  2.   

    文件编码不是UTF-8,用ultraedit打开,在文件菜单中选择转换-->asc2到UTF-8(Unicode)
      

  3.   

    出错肯定是原代码?客户端传的XML格的POST数据与是原代码中直接写的,这样另存为有用吗?
      

  4.   

    你试试写个过滤器 给字符都转成UTF-8
      

  5.   

    <META http-equiv=Content-Type content="text/html; charset="UTF-8">
                                                              ^
                                                              ^
                                                              ^
                                                            没写错?