欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

java 解决异常 2 字节的 UTF-8 序列的字节2 无效的问题

程序员文章站 2024-03-11 12:42:25
java 解决异常 2 字节的 utf-8 序列的字节 2 无效的问题         ...

java 解决异常 2 字节的 utf-8 序列的字节 2 无效的问题

         最近做项目,遇到异常 2 字节的 utf-8 序列的字节 2 无效的问题,上网找了下资料,这里记录下解决方法,有遇到同样问题的大家,可以看下

详细异常:

十二月 08, 2015 7:16:55 下午 org.apache.catalina.core.standardwrappervalve invoke
严重: servlet.service() for servlet [jsp] in context with path [/test] threw exception [org.apache.jasper.jasperexception: xml parsing error on file org.apache.tomcat.util.scan.mergedwebxml] with root cause
com.sun.org.apache.xerces.internal.impl.io.malformedbytesequenceexception: 2 字节的 utf-8 序列的字节 2 无效。
 at com.sun.org.apache.xerces.internal.impl.io.utf8reader.invalidbyte(utf8reader.java:687)
 at com.sun.org.apache.xerces.internal.impl.io.utf8reader.read(utf8reader.java:372)
 at com.sun.org.apache.xerces.internal.impl.xmlentityscanner.load(xmlentityscanner.java:1753)
 at com.sun.org.apache.xerces.internal.impl.xmlentityscanner.peekchar(xmlentityscanner.java:497)
 at com.sun.org.apache.xerces.internal.impl.xmldocumentfragmentscannerimpl$fragmentcontentdriver.next(xmldocumentfragmentscannerimpl.java:2710)
 at com.sun.org.apache.xerces.internal.impl.xmldocumentscannerimpl.next(xmldocumentscannerimpl.java:606)
 at com.sun.org.apache.xerces.internal.impl.xmlnsdocumentscannerimpl.next(xmlnsdocumentscannerimpl.java:117)
 at com.sun.org.apache.xerces.internal.impl.xmldocumentfragmentscannerimpl.scandocument(xmldocumentfragmentscannerimpl.java:510)
 at com.sun.org.apache.xerces.internal.parsers.xml11configuration.parse(xml11configuration.java:848)
 at com.sun.org.apache.xerces.internal.parsers.xml11configuration.parse(xml11configuration.java:777)
 at com.sun.org.apache.xerces.internal.parsers.xmlparser.parse(xmlparser.java:141)
 at com.sun.org.apache.xerces.internal.parsers.domparser.parse(domparser.java:243)
 at com.sun.org.apache.xerces.internal.jaxp.documentbuilderimpl.parse(documentbuilderimpl.java:347)
 at org.apache.jasper.xmlparser.parserutils.parsexmldocument(parserutils.java:96)
 at org.apache.jasper.compiler.jspconfig.processwebdotxml(jspconfig.java:83)
 at org.apache.jasper.compiler.jspconfig.init(jspconfig.java:231)
 at org.apache.jasper.compiler.jspconfig.findjspproperty(jspconfig.java:290)
 at org.apache.jasper.compiler.compiler.generatejava(compiler.java:113)
 at org.apache.jasper.compiler.compiler.compile(compiler.java:365)
 at org.apache.jasper.compiler.compiler.compile(compiler.java:345)
 at org.apache.jasper.compiler.compiler.compile(compiler.java:332)
 at org.apache.jasper.jspcompilationcontext.compile(jspcompilationcontext.java:594)
 at org.apache.jasper.servlet.jspservletwrapper.service(jspservletwrapper.java:342)
 at org.apache.jasper.servlet.jspservlet.servicejspfile(jspservlet.java:391)
 at org.apache.jasper.servlet.jspservlet.service(jspservlet.java:334)
 at javax.servlet.http.httpservlet.service(httpservlet.java:722)
 at org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:306)
 at org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:210)
 at com.alibaba.druid.support.http.webstatfilter.dofilter(webstatfilter.java:123)
 at org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:244)
 at org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:210)
 at org.apache.struts2.dispatcher.ng.filter.strutsexecutefilter.dofilter(strutsexecutefilter.java:90)
 at org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:244)
 at org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:210)
 at org.apache.struts2.dispatcher.ng.filter.strutspreparefilter.dofilter(strutspreparefilter.java:91)
 at org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:244)
 at org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:210)
 at com.huaqin.dmt.filter.acl.dofilter(acl.java:251)
 at org.springframework.web.filter.delegatingfilterproxy.invokedelegate(delegatingfilterproxy.java:346)
 at org.springframework.web.filter.delegatingfilterproxy.dofilter(delegatingfilterproxy.java:259)
 at org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:244)
 at org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:210)
 at com.huaqin.dmt.filter.characterencodingfilter.dofilter(characterencodingfilter.java:38)
 at org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:244)
 at org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:210)
 at org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:240)
 at org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:161)
 at org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:164)
 at org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:100)
 at org.apache.catalina.valves.accesslogvalve.invoke(accesslogvalve.java:550)
 at org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:118)
 at org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:380)
 at org.apache.coyote.http11.http11processor.process(http11processor.java:243)
 at org.apache.coyote.http11.http11protocol$http11connectionhandler.process(http11protocol.java:188)
 at org.apache.coyote.http11.http11protocol$http11connectionhandler.process(http11protocol.java:166)
 at org.apache.tomcat.util.net.jioendpoint$socketprocessor.run(jioendpoint.java:288)
 at java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1145)
 at java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:615)
 at java.lang.thread.run(thread.java:744)

解决方法:

在tomcat的bin目录下有文件catalina.bat

找到这行:set java_opts=%java_opts% %logging_config%

在它上一行加入:set java_opts=-server -dfile.encoding=utf-8

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!