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()的双字节与单字节的不一致,请各位帮忙指出如何更进!
<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()的双字节与单字节的不一致,请各位帮忙指出如何更进!
通过editplug之类的打开,另存为 选择utf-8编码 就OK了
^
^
^
没写错?