标签:无法找到servlet invalid byte 2 of 2-byte utf-8 sequence web.xml文本格式
今天特别有成就感, 感谢上帝,是他让我不轻易放弃。好了下面简单介绍一下我的问题。我最近在学习 Headfirst servlet JSP 第81页面关于部署一个小应用。但是无论怎么调试无法找到servlet,最开始是web.xml里面的servlet和servlet-mapping位置放错了,在这里也提醒一下各位,请一定要仔细检查这个部署文件,确定没有错。
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<description>My first web app in Java.</description>
<display-name>My Web App</display-name>
<servlet>
<servlet-name>ch3beer</servlet-name><!--这是一个虚构的名字,只能够在描述文件中使用-->
<servlet-class>example.BeerSelect</servlet-class><!--这是一个Servlet的完全限定名字-->
</servlet>
<!--这里将这个名字映射到供给外部访问用-->
<servlet-mapping>
<servlet-name>ch3beer</servlet-name>
<url-pattern>/Sb.do</url-pattern>
</servlet-mapping>
</web-app>
把web.xml弄好了之后,再运行,仍然无法找到servlet,通过查询Tomcat的catalina.2014-05-17.log,发现有如下的错误,红色为错误的问题。
May 17, 2014 11:14:17 AM org.apache.catalina.startup.ContextConfig applicationWebConfig
SEVERE: Parse error in application web.xml file at jndi:/localhost/beer-v1/WEB-INF/web.xml
com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 2 of 2-byte UTF-8 sequence.
at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(UTF8Reader.java:684)
at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(UTF8Reader.java:369)
at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(XMLEntityScanner.java:1742)
at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.scanData(XMLEntityScanner.java:1242)
at com.sun.org.apache.xerces.internal.impl.XMLScanner.scanComment(XMLScanner.java:756)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanComment(XMLDocumentFragmentScannerImpl.java:1040)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2954)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1675)
at org.apache.catalina.startup.ContextConfig.applicationWebConfig(ContextConfig.java:365)
at org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:1045)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:265)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4616)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:583)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1079)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1002)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:506)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:822)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
然后通过Google查询到一篇帖子:http://stackoverflow.com/questions/9920758/malformedbytesequenceexception-invalid-byte-2-of-2-byte-utf-8-sequence
通过查询这个帖子,得到一些提示可能是web.xml文本的格式问题。想了一下的确有可能,因为我是首先新建立一个文本文件,然后通过修改后缀名称为xml.最后通过文本编辑软件Notepad++将web.xml转换成utf-8,然后重启一下tomcat服务就解决这个问题。哈哈,真心不知道,web.xml还有这个讲究啊,希望能够帮助其他的一些朋友。
附录-utf-8维基的解释,utf-8目前普遍用在互联网数据的编码上面。
http://en.wikipedia.org/wiki/UTF-8
UTF-8 has become the dominant character encoding for the World Wide Web, accounting for more than half of all Web pages。
Tomcat部署servlet小应用无法找到相应的servlet类的问题可能原因,布布扣,bubuko.com
Tomcat部署servlet小应用无法找到相应的servlet类的问题可能原因
标签:无法找到servlet invalid byte 2 of 2-byte utf-8 sequence web.xml文本格式
原文地址:http://oscarjia.blog.51cto.com/2761520/1412802