`
Kevin12
  • 浏览: 234804 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

org.dom4j.DocumentException:Invalid byte 2 of 2-byte UTF-8 sequence

    博客分类:
  • Java
阅读更多
今天做工作流项目(jbpm4),将流程文件导出成xml到客户端后,编码格式是utf-8的,在本地将导出的xml导入到mysql数据库中是正常的,但是将该项目打成war包后放到虚拟机中的tomcat中,运行虚拟机中的tomcat,并访问项目时候,导出的也是utf-8的xml文件,但是再将该文件导入到mysql数据库时候却出现下面的错误:
org.dom4j.DocumentException: Invalid byte 1 of 1-byte UTF-8 sequence. Nested exception: Invalid byte 1 of 1-byte UTF-8 sequence.  
    at org.dom4j.io.SAXReader.read(SAXReader.java:484)  
    at org.dom4j.io.SAXReader.read(SAXReader.java:321)  
    at com.dataoperate.PaseXml.pXml(PaseXml.java:28)  
    at com.dataoperate.JdbcOp.insertDb(JdbcOp.java:30)  
    at com.dataoperate.JdbcOp.main(JdbcOp.java:89) 

google了一下找到了下面的解决方法:
将原先导出的流程xml文件中的编码格式由“utf-8”改成“gbk”后保存,再导入就可以了。
仔细分析原因,我的本地电脑用的是win 7 ,而虚拟机中的系统使用的想xp系统。在中文版的window下java的默认的编码为GBK,虽然我们标识了要将xml保存为utf-8格式但实际上文件是以GBK格式来保存的,所以这也就是为什么能够我们使用GBK、GB2312编码来生成xml文件能正确的被解析,而以UTF-8格式生成的文件不能被xml解析器所解析的原因。
给我解决思路的来源如chenyanbo所说:
http://blog.csdn.net/chenyanbo/article/details/6866941

下面是我的一个导出的流程xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<root><TbBWebWorkflOwMain id="1000118"><node id="1000118"><wwmWorkflowId id="1000118">1000118</wwmWorkflowId><wwmWorkflowName id="1000118">test20</wwmWorkflowName><wwmWorkflowVersion id="1000118">1</wwmWorkflowVersion><wwmWorkflowIspress id="1000118"></wwmWorkflowIspress><wwmWorkflowIsemail id="1000118"></wwmWorkflowIsemail><wwmWorkflowIssms id="1000118"></wwmWorkflowIssms><wwmWorkflowXml id="1000118">
&lt;process-definition xmlns="http://jbpm.org/4.4/jpdl" name="aaaa" key="aaaa"&gt;&lt;task xmlns="" name="任务1" g="221,360,72,32"&gt;&lt;assignment-handler class="com.sense.workflow.core.FirstAssigneeHandler"/&gt;&lt;description&gt;164D9B9892EA4C9C95D5972CBCF2AC14&lt;/description&gt;&lt;transition name="任务2" to="任务2"/&gt;&lt;/task&gt;&lt;start xmlns="" name="开始" g="241,290,32,32"&gt;&lt;transition name="任务1" to="任务1"/&gt;&lt;/start&gt;&lt;end xmlns="" name="结束" g="240,530,32,32"/&gt;&lt;task xmlns="" name="任务3" g="220,480,72,32"&gt;&lt;assignment-handler class="com.sense.workflow.core.CustomAssigneeHandler"/&gt;&lt;description&gt;FBBC22F3502C4C84B061A9E7034DD2F6&lt;/description&gt;&lt;transition name="结束" to="结束"/&gt;&lt;/task&gt;&lt;task xmlns="" name="任务2" g="220,420,72,32"&gt;&lt;assignment-handler class="com.sense.workflow.core.CustomAssigneeHandler"/&gt;&lt;description&gt;24820DFF666A437A877054582FD1E246&lt;/description&gt;&lt;transition name="任务3" to="任务3"/&gt;&lt;/task&gt;&lt;migrate-instances/&gt;&lt;/process-definition&gt;</wwmWorkflowXml><wwmWorkflowMemo id="1000118"></wwmWorkflowMemo><wwnWorkflowIsrelease id="1000118">1</wwnWorkflowIsrelease><wwnWorkflowReleaseTime id="1000118">2013-09-09 13:17:41.0</wwnWorkflowReleaseTime><wwmCreateDatetime id="1000118">2012-11-20 10:19:41.0</wwmCreateDatetime><wwmLastUpdateDatetime id="1000118">2013-09-09 14:49:12.0</wwmLastUpdateDatetime><wwmLastUpdateOperatorId id="1000118"></wwmLastUpdateOperatorId><wwmWorkflowKey id="1000118">aaaa</wwmWorkflowKey></node></TbBWebWorkflOwMain><TbBWebWorkflOwNode id="1000420"><node id="1000420"><wwnNodeId id="1000420">1000420</wwnNodeId><wwnWwmWorkflowId id="1000420">1000118</wwnWwmWorkflowId><wwnWwmWorkflowName id="1000420">test20</wwnWwmWorkflowName><wwnNodeStepNumber id="1000420">1</wwnNodeStepNumber><wwnNodeName id="1000420">任务1</wwnNodeName><wwnNodeDescription id="1000420">164D9B9892EA4C9C95D5972CBCF2AC14</wwnNodeDescription><wwnNodeType id="1000420">1</wwnNodeType><wwnFormInfo id="1000420">noForm.jsp</wwnFormInfo><wwnTransreadToPeople id="1000420">{"chuanyueType":"1","display":"乐天","config":"82E6911F5DC0419680C65451C0A2CF71"}</wwnTransreadToPeople><wwnTransemailToPeople id="1000420"></wwnTransemailToPeople><wwnLuyouConfig id="1000420">{"lyType":0,"config":[2]}</wwnLuyouConfig><wwnRightConfig id="1000420">{"isRevoke":0,"isCircular":1,"isManualCirculate":1,"isAttachment":1,"isAssign":1,"returnConfig":{"returnType":"0","returnStep":[]}}</wwnRightConfig><wwnPressConfig id="1000420">{"isPress":"0","isEmail":"1","pressTimes":"1","pressInterval":"1"}</wwnPressConfig><wwnAssignConfig id="1000420">{"assignType":[2],"config":[["1"]]}</wwnAssignConfig><wwnHuqianConfig id="1000420"></wwnHuqianConfig><wwnXmlText id="1000420">
&lt;root&gt;&lt;start&gt;&lt;transition to="任务1"/&gt;&lt;/start&gt;&lt;task name="任务1" form="noForm.jsp"&gt;&lt;assignment-handler class="com.sense.workflow.core.FirstAssigneeHandler"/&gt;&lt;description&gt;164D9B9892EA4C9C95D5972CBCF2AC14&lt;/description&gt;&lt;transition name="2" to="2"/&gt;&lt;/task&gt;&lt;/root&gt;</wwnXmlText><wwnCreateDatetime id="1000420">2012-11-20 10:19:41.0</wwnCreateDatetime><wwnLastUpdateDatetime id="1000420">2013-09-09 14:49:12.0</wwnLastUpdateDatetime><wwnLastUpdateOperatorId id="1000420"></wwnLastUpdateOperatorId></node><node id="1000421"><wwnNodeId id="1000421">1000421</wwnNodeId><wwnWwmWorkflowId id="1000421">1000118</wwnWwmWorkflowId><wwnWwmWorkflowName id="1000421">test20</wwnWwmWorkflowName><wwnNodeStepNumber id="1000421">2</wwnNodeStepNumber><wwnNodeName id="1000421">任务2</wwnNodeName><wwnNodeDescription id="1000421">24820DFF666A437A877054582FD1E246</wwnNodeDescription><wwnNodeType id="1000421">1</wwnNodeType><wwnFormInfo id="1000421">noForm.jsp</wwnFormInfo><wwnTransreadToPeople id="1000421">{"chuanyueType":"0","display":"","config":""}</wwnTransreadToPeople><wwnTransemailToPeople id="1000421"></wwnTransemailToPeople><wwnLuyouConfig id="1000421">{"lyType":0,"config":[3]}</wwnLuyouConfig><wwnRightConfig id="1000421">{"isRevoke":0,"isCircular":0,"isManualCirculate":1,"isAttachment":1,"isAssign":1,"returnConfig":{"returnType":"0","returnStep":[]}}</wwnRightConfig><wwnPressConfig id="1000421">{"isPress":"0","isEmail":"1","pressTimes":"1","pressInterval":"1"}</wwnPressConfig><wwnAssignConfig id="1000421">{"assignType":[2],"config":[["1"]]}</wwnAssignConfig><wwnHuqianConfig id="1000421"></wwnHuqianConfig><wwnXmlText id="1000421">
&lt;root&gt;&lt;task name="任务2" form="noForm.jsp"&gt;&lt;assignment-handler class="com.sense.workflow.core.CustomAssigneeHandler"/&gt;&lt;description&gt;24820DFF666A437A877054582FD1E246&lt;/description&gt;&lt;transition name="3" to="3"/&gt;&lt;/task&gt;&lt;/root&gt;</wwnXmlText><wwnCreateDatetime id="1000421">2012-11-20 10:19:41.0</wwnCreateDatetime><wwnLastUpdateDatetime id="1000421">2013-09-09 14:49:12.0</wwnLastUpdateDatetime><wwnLastUpdateOperatorId id="1000421"></wwnLastUpdateOperatorId></node><node id="1000422"><wwnNodeId id="1000422">1000422</wwnNodeId><wwnWwmWorkflowId id="1000422">1000118</wwnWwmWorkflowId><wwnWwmWorkflowName id="1000422">test20</wwnWwmWorkflowName><wwnNodeStepNumber id="1000422">3</wwnNodeStepNumber><wwnNodeName id="1000422">任务3</wwnNodeName><wwnNodeDescription id="1000422">FBBC22F3502C4C84B061A9E7034DD2F6</wwnNodeDescription><wwnNodeType id="1000422">1</wwnNodeType><wwnFormInfo id="1000422">noForm.jsp</wwnFormInfo><wwnTransreadToPeople id="1000422">{"chuanyueType":"0","display":"","config":""}</wwnTransreadToPeople><wwnTransemailToPeople id="1000422"></wwnTransemailToPeople><wwnLuyouConfig id="1000422">{"lyType":0,"config":[4]}</wwnLuyouConfig><wwnRightConfig id="1000422">{"isRevoke":0,"isCircular":0,"isManualCirculate":0,"isAttachment":1,"isAssign":1,"returnConfig":{"returnType":"3","returnStep":[]}}</wwnRightConfig><wwnPressConfig id="1000422">{"isPress":"0","isEmail":"1","pressTimes":"1","pressInterval":"1"}</wwnPressConfig><wwnAssignConfig id="1000422">{"assignType":[2],"config":[["1"]]}</wwnAssignConfig><wwnHuqianConfig id="1000422"></wwnHuqianConfig><wwnXmlText id="1000422">
&lt;root&gt;&lt;task name="任务3" form="noForm.jsp"&gt;&lt;assignment-handler class="com.sense.workflow.core.CustomAssigneeHandler"/&gt;&lt;description&gt;FBBC22F3502C4C84B061A9E7034DD2F6&lt;/description&gt;&lt;transition name="4" to="4"/&gt;&lt;/task&gt;&lt;/root&gt;</wwnXmlText><wwnCreateDatetime id="1000422">2012-11-20 10:19:41.0</wwnCreateDatetime><wwnLastUpdateDatetime id="1000422">2013-09-09 14:49:12.0</wwnLastUpdateDatetime><wwnLastUpdateOperatorId id="1000422"></wwnLastUpdateOperatorId></node><node id="1000423"><wwnNodeId id="1000423">1000423</wwnNodeId><wwnWwmWorkflowId id="1000423">1000118</wwnWwmWorkflowId><wwnWwmWorkflowName id="1000423">test20</wwnWwmWorkflowName><wwnNodeStepNumber id="1000423">4</wwnNodeStepNumber><wwnNodeName id="1000423">结束</wwnNodeName><wwnNodeDescription id="1000423">15D72A74A5B5439593AA0558AA940E78</wwnNodeDescription><wwnNodeType id="1000423">6</wwnNodeType><wwnFormInfo id="1000423">noForm.jsp</wwnFormInfo><wwnTransreadToPeople id="1000423">{"display":"","config":"","chuanyueType":0}</wwnTransreadToPeople><wwnTransemailToPeople id="1000423"></wwnTransemailToPeople><wwnLuyouConfig id="1000423">{"config":[],"lyType":0}</wwnLuyouConfig><wwnRightConfig id="1000423">{"isCircular":0,"isAttachment":1,"isAssign":0,"returnConfig":{"returnType":0},"isRevoke":0}</wwnRightConfig><wwnPressConfig id="1000423">{"pressTimes":"0","isEmail":"1","isPress":0,"pressInterval":"0"}</wwnPressConfig><wwnAssignConfig id="1000423">{"assignType":[],"config":[]}</wwnAssignConfig><wwnHuqianConfig id="1000423"></wwnHuqianConfig><wwnXmlText id="1000423">&lt;end name="结束"/&gt;</wwnXmlText><wwnCreateDatetime id="1000423">2012-11-20 10:19:41.0</wwnCreateDatetime><wwnLastUpdateDatetime id="1000423">2013-09-09 14:49:12.0</wwnLastUpdateDatetime><wwnLastUpdateOperatorId id="1000423"></wwnLastUpdateOperatorId></node></TbBWebWorkflOwNode></root>
分享到:
评论

相关推荐

    org.dom4j.jar

    当我们遇到“java.lang.ClassNotFoundException: org.dom4j.DocumentException”的错误提示时,这通常意味着系统中缺少了DOM4j库,只需将“org.dom4j.jar”添加到项目类路径中即可解决此问题。 DOM4J是基于DOM和SAX...

    itextpdf5.4.3+itextasian5.2.0

    解决 com.itextpdf.text.DocumentException: Font 'STSongStd-Light' with 'UniGB-UCS2-H' is not recognized. 亲测可用!

    dom4j基础入门文档(SAX,DOM,XPATH)

    8. `org.dom4j.ElementHandler`: 提供了处理Element对象的方法,用于自定义元素处理逻辑。 9. `org.dom4j.ElementPath`: 用于ElementHandler,提供当前处理路径层次的信息。 10. `org.dom4j.Entity`: 定义XML实体,...

    使用 dom4j 解析 XML

    1. **下载`dom4j`库**:可以从官方网站http://dom4j.org/下载`dom4j`的最新版本,通常包括`dom4j-full.jar`或`dom4j.jar`等文件。 2. **配置ClassPath**:将下载的jar文件添加到项目的ClassPath中。如果是`dom4j-...

    dom4j解析xml详解,包含源代码,dom4j.jar包

    import org.dom4j.DocumentException; import org.dom4j.io.SAXReader; public class Dom4JExample { public static void main(String[] args) { try { SAXReader reader = new SAXReader(); Document document...

    dom4j解析字符串

    首先,我们import dom4j的相关类,包括Document、DocumentException、DocumentHelper和Element等。然后,我们使用DocumentHelper.parseText方法来解析XML字符串,并获取根元素。最后,我们可以使用Element对象的方法...

    dom4j document

    * @throws org.dom4j.DocumentException occurs whenever the build process fails. */ public void parseWithSAX(File aFile) throws DocumentException { SAXReader xmlReader = new SAXReader(); this.doc =...

    dom4j demo 使用

    import org.dom4j.DocumentException; import org.dom4j.DocumentFactory; import org.dom4j.Element; import org.dom4j.io.SAXReader; public class Dom4jDemo { public static void main(String[] args) { try ...

    dom4j -1.6.1 源码 dom4j -1.6.1 源码

    4. **异常处理**: dom4j在源码中广泛使用了异常处理机制,如`DocumentException`和`IOException`,确保在处理XML时能捕获并处理可能出现的问题。 **五、使用示例** 以下是一个简单的dom4j使用示例: ```java import...

    dom4j的使用+dom4j.jar

    import org.dom4j.DocumentException; import org.dom4j.Element; import org.dom4j.io.SAXReader; public class Dom4JExample { public static void main(String[] args) { try { SAXReader reader = new ...

    使用dom4j读取xml四种方法

    ### 使用dom4j读取XML的四种方法 在Java开发中,处理XML文件是一种常见的需求。Dom4j作为一款简洁高效的Java库,被广泛应用于解析、操作XML文档。本文将详细介绍使用dom4j读取XML文件的四种常见方法,并通过示例...

    Dom4j封装和解析

    import org.dom4j.DocumentException; import org.dom4j.io.SAXReader; public class Dom4jExample { public static void main(String[] args) { try { SAXReader reader = new SAXReader(); Document document...

    Dom4j解析XML及中文问题

    import org.dom4j.DocumentException; import org.dom4j.DocumentFactory; import org.dom4j.Element; import java.io.File; public class Dom4jExample { public static void main(String[] args) { try { // ...

    dom4j 解析(读取) xml 节点数据

    import org.dom4j.DocumentException; import org.dom4j.Element; import org.dom4j.io.SAXReader; ``` 接下来,我们将创建一个`SAXReader`实例,它是DOM4J中的解析器,用于读取XML文件: ```java SAXReader ...

    dom4j入门例子

    import org.dom4j.DocumentException; import org.dom4j.io.SAXReader; public class ParseXML { public static void main(String[] args) { SAXReader reader = new SAXReader(); try { Document document = ...

    dom4j解析xml文件代码示例

    import org.dom4j.DocumentException; import org.dom4j.io.SAXReader; File file = new File("emailTemplateConfig.xml"); SAXReader reader = new SAXReader(); try { Document document = reader.read(file); }...

    java_Dom4j解析XML详解

    import org.dom4j.DocumentException; import org.dom4j.Element; import org.dom4j.io.SAXReader; public class Dom4jExample { public static void main(String[] args) { try { // 创建SAXReader对象 ...

    使用dom4j生成和读取hibernate.cfg.xml

    import org.dom4j.DocumentException; import org.dom4j.io.SAXReader; // 创建DocumentBuilder SAXReader reader = new SAXReader(); try { // 读取XML文件 Document doc = reader.read(new File("path/to/...

    dom4j基于事件流解析大XML的文件 示例

    import org.dom4j.DocumentException; import org.dom4j.io.SAXReader; import org.xml.sax.helpers.DefaultHandler; public class Dom4jSaxExample { public static void main(String[] args) { SAXReader ...

Global site tag (gtag.js) - Google Analytics