论坛首页 Java企业应用论坛

遇到异常:Invalid byte 2 of 2-byte UTF-8 sequence

浏览 12067 次
该帖已经被评为隐藏帖
作者 正文
   发表时间:2008-03-28  
hibernat template查询时抛出。应该是解析XML文件编码错误,但没提示是哪个文件。
基本已经排除了以下问题:tomcat版本(开始怀疑是jsper.jar版本) ,数据库字符集,JSP/项目配置文件编码(后来怀疑是jsp或xml文件UTF8 BOM问题,但都一一查过不是)。
现在怀疑是某个jar文件里的xml问题。

原来有人遇到过:http://www.iteye.com/topic/1886
但我的不知道是哪个文件的错误,而且时好时坏,一般查询有结果时就会有异常。

很郁闷啊,搞了一天没搞定
今天解决了哈哈,竟然是JSP的错误,struts-config里定义了exception的xxx.jsp文件(刚接手这个混乱的项目还不熟悉),结果这个文件编码有问题,抛异常时解析xxx.jsp就出现了上述错误。Debug过程:下载Tomcat源码jspser包调试,发现了这个jsp文件。

异常如下:
2008-3-28 16:34:21 org.apache.catalina.core.ApplicationDispatcher invoke
严重: Servlet.service() for servlet jsp threw exception
java.io.UTFDataFormatException: Invalid byte 2 of 2-byte UTF-8 sequence.
    at org.apache.jasper.xmlparser.UTF8Reader.invalidByte(UTF8Reader.java:621)
    at org.apache.jasper.xmlparser.UTF8Reader.read(UTF8Reader.java:310)
    at org.apache.jasper.xmlparser.XMLEncodingDetector.load(XMLEncodingDetector.java:1007)
    at org.apache.jasper.xmlparser.XMLEncodingDetector.skipString(XMLEncodingDetector.java:958)
    at org.apache.jasper.xmlparser.XMLEncodingDetector.scanXMLDecl(XMLEncodingDetector.java:1216)
    at org.apache.jasper.xmlparser.XMLEncodingDetector.getEncoding(XMLEncodingDetector.java:122)
    at org.apache.jasper.xmlparser.XMLEncodingDetector.getEncoding(XMLEncodingDetector.java:110)
    at org.apache.jasper.compiler.ParserController.determineSyntaxAndEncoding(ParserController.java:308)
    at org.apache.jasper.compiler.ParserController.doParse(ParserController.java:172)
    at org.apache.jasper.compiler.ParserController.parse(ParserController.java:102)
    at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:167)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:306)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
    at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:308)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:687)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:469)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:403)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
    at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1062)
    at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:263)
    at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:386)
    at org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:318)
    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:229)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
    at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:75)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:228)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:216)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:634)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:445)
    at java.lang.Thread.run(Thread.java:595)
2008-3-28 16:34:21 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet action threw exception
java.io.UTFDataFormatException: Invalid byte 2 of 2-byte UTF-8 sequence.
    at org.apache.jasper.xmlparser.UTF8Reader.invalidByte(UTF8Reader.java:621)
    at org.apache.jasper.xmlparser.UTF8Reader.read(UTF8Reader.java:310)
    at org.apache.jasper.xmlparser.XMLEncodingDetector.load(XMLEncodingDetector.java:1007)
    at org.apache.jasper.xmlparser.XMLEncodingDetector.skipString(XMLEncodingDetector.java:958)
    at org.apache.jasper.xmlparser.XMLEncodingDetector.scanXMLDecl(XMLEncodingDetector.java:1216)
    at org.apache.jasper.xmlparser.XMLEncodingDetector.getEncoding(XMLEncodingDetector.java:122)
    at org.apache.jasper.xmlparser.XMLEncodingDetector.getEncoding(XMLEncodingDetector.java:110)
    at org.apache.jasper.compiler.ParserController.determineSyntaxAndEncoding(ParserController.java:308)
    at org.apache.jasper.compiler.ParserController.doParse(ParserController.java:172)
    at org.apache.jasper.compiler.ParserController.parse(ParserController.java:102)
    at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:167)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:306)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
    at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:308)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:687)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:469)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:403)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
    at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1062)
    at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:263)
    at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:386)
    at org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:318)
    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:229)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
    at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:75)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:228)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:216)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:634)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:445)
    at java.lang.Thread.run(Thread.java:595)

论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics