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文件:

1000118test201
<process-definition xmlns="http://jbpm.org/4.4/jpdl" name="aaaa" key="aaaa"><task xmlns="" name="任务1" g="221,360,72,32"><assignment-handler class="com.sense.workflow.core.FirstAssigneeHandler"/><description>164D9B9892EA4C9C95D5972CBCF2AC14</description><transition name="任务2" to="任务2"/></task><start xmlns="" name="开始" g="241,290,32,32"><transition name="任务1" to="任务1"/></start><end xmlns="" name="结束" g="240,530,32,32"/><task xmlns="" name="任务3" g="220,480,72,32"><assignment-handler class="com.sense.workflow.core.CustomAssigneeHandler"/><description>FBBC22F3502C4C84B061A9E7034DD2F6</description><transition name="结束" to="结束"/></task><task xmlns="" name="任务2" g="220,420,72,32"><assignment-handler class="com.sense.workflow.core.CustomAssigneeHandler"/><description>24820DFF666A437A877054582FD1E246</description><transition name="任务3" to="任务3"/></task><migrate-instances/></process-definition>12013-09-09 13:17:41.02012-11-20 10:19:41.02013-09-09 14:49:12.0aaaa10004201000118test201任务1164D9B9892EA4C9C95D5972CBCF2AC141noForm.jsp{"chuanyueType":"1","display":"乐天","config":"82E6911F5DC0419680C65451C0A2CF71"}{"lyType":0,"config":[2]}{"isRevoke":0,"isCircular":1,"isManualCirculate":1,"isAttachment":1,"isAssign":1,"returnConfig":{"returnType":"0","returnStep":[]}}{"isPress":"0","isEmail":"1","pressTimes":"1","pressInterval":"1"}{"assignType":[2],"config":[["1"]]}
<root><start><transition to="任务1"/></start><task name="任务1" form="noForm.jsp"><assignment-handler class="com.sense.workflow.core.FirstAssigneeHandler"/><description>164D9B9892EA4C9C95D5972CBCF2AC14</description><transition name="2" to="2"/></task></root>2012-11-20 10:19:41.02013-09-09 14:49:12.010004211000118test202任务224820DFF666A437A877054582FD1E2461noForm.jsp{"chuanyueType":"0","display":"","config":""}{"lyType":0,"config":[3]}{"isRevoke":0,"isCircular":0,"isManualCirculate":1,"isAttachment":1,"isAssign":1,"returnConfig":{"returnType":"0","returnStep":[]}}{"isPress":"0","isEmail":"1","pressTimes":"1","pressInterval":"1"}{"assignType":[2],"config":[["1"]]}
<root><task name="任务2" form="noForm.jsp"><assignment-handler class="com.sense.workflow.core.CustomAssigneeHandler"/><description>24820DFF666A437A877054582FD1E246</description><transition name="3" to="3"/></task></root>2012-11-20 10:19:41.02013-09-09 14:49:12.010004221000118test203任务3FBBC22F3502C4C84B061A9E7034DD2F61noForm.jsp{"chuanyueType":"0","display":"","config":""}{"lyType":0,"config":[4]}{"isRevoke":0,"isCircular":0,"isManualCirculate":0,"isAttachment":1,"isAssign":1,"returnConfig":{"returnType":"3","returnStep":[]}}{"isPress":"0","isEmail":"1","pressTimes":"1","pressInterval":"1"}{"assignType":[2],"config":[["1"]]}
<root><task name="任务3" form="noForm.jsp"><assignment-handler class="com.sense.workflow.core.CustomAssigneeHandler"/><description>FBBC22F3502C4C84B061A9E7034DD2F6</description><transition name="4" to="4"/></task></root>2012-11-20 10:19:41.02013-09-09 14:49:12.010004231000118test204结束15D72A74A5B5439593AA0558AA940E786noForm.jsp{"display":"","config":"","chuanyueType":0}{"config":[],"lyType":0}{"isCircular":0,"isAttachment":1,"isAssign":0,"returnConfig":{"returnType":0},"isRevoke":0}{"pressTimes":"0","isEmail":"1","isPress":0,"pressInterval":"0"}{"assignType":[],"config":[]}<end name="结束"/>2012-11-20 10:19:41.02013-09-09 14:49:12.0

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