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

今天做工作流项目(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>

你可能感兴趣的:(java,tomcat,mysql,xml,jbpm)