[英]com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException parsing XML in POST (Java Servlet)
I am developing a Servlet which uses a POST to send the information. 我正在开发一个使用POST发送信息的Servlet。 I am getting an exception depending where the servlet is deployed. 根据servlet的部署位置,我遇到了一个异常。 If I deploy on a local JBoss EAP 7 it works like a charm. 如果我在本地JBoss EAP 7上进行部署,它的工作原理就像一个魅力。 But, if I deploy into a remote server (JBoss EAP 7 too) i am getting the following error: 但是,如果我部署到远程服务器(也是JBoss EAP 7)中,则会出现以下错误:
CODE 码
final InputStream is = new ByteArrayInputStream(xml);
doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(is);
ERROR 错误
<message>
Failed to load XML: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Byte no válido 2 de la secuencia UTF-8 de 4 bytes
~ôJ뢺ÞjX³jwh•ªkyø«™§¬‚†Ú~*æiÊ+x„ÅÇ©¶*'ºè©`zw«j¹Z~*æip(Ú½©Z </message>
For more information the servlet has a jboss-deployment-structure.xml 有关更多信息,servlet具有jboss-deployment-structure.xml
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">
<deployment>
<dependencies>
<module name="javax.api"/>
<module name="org.apache.santuario.xmlsec"/>
<module name="org.apache.xerces" />
<system export="true">
<paths>
<path name="com/sun/org/apache/xerces/internal/dom"/>
</paths>
</system>
</dependencies>
</deployment>
</jboss-deployment-structure>
Where the xerces library is implicated. 涉及xerces库的位置。 I don´t understand if my problem is related to that xml , or I should change some encoding in the server/servlet code. 我不知道我的问题是否与该xml有关,或者我应该更改服务器/ servlet代码中的某些编码。 Thnaks in advance. 提前想一下。
Badulake, Badulake,
What you are hitting looks like a encoding issue. 您遇到的问题似乎是编码问题。 When you don't specify encoding while converting a byte array to Java string, JVM uses the default encoding of the platform. 当您在将字节数组转换为Java字符串时未指定编码时,JVM将使用平台的默认编码。 In most cases the default encoding is utf-8 and that works great. 在大多数情况下,默认编码为utf-8,效果很好。 However I have seen many OS installations where the encoding is simply US-ASCII. 但是,我已经看到许多操作系统安装,其中的编码仅仅是US-ASCII。
If this is your issue, you can either set the default encoding as a JVM option on the Java command line or change the encoding on the platform to utf-8. 如果这是您的问题,则可以在Java命令行上将默认编码设置为JVM选项,也可以将平台上的编码更改为utf-8。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.