自己在虚拟机里开发一个小系统,做练手用,平时都运行好好的,最近一两个星期都没动了,今天兴致一来,想写点东西。启动tomcat,能访问到登陆页面,但是输入正确的用户名和密码,点击登陆之后,浏览器上报出异常:HTTP Status 404 - Servlet action is not available 。

而tomcat日志则是这样的异常信息:

- Initializing, config='org.apache.struts.util.LocalStrings', returnNull=true
- Initializing, config='org.apache.struts.action.ActionResources', returnNull=true
- Parsing error processing resource path
java.net.UnknownHostException: struts.apache.org
 at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)
 at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
 at java.net.Socket.connect(Socket.java:579)
 at java.net.Socket.connect(Socket.java:528)
 at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
 at sun.net.www.http.HttpClient.openServer(HttpClient.java:388)
 at sun.net.www.http.HttpClient.openServer(HttpClient.java:483)
 at sun.net.www.http.HttpClient.<init>(HttpClient.java:213)
 at sun.net.www.http.HttpClient.New(HttpClient.java:300)
 at sun.net.www.http.HttpClient.New(HttpClient.java:316)
 at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:992)
 at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:928)
 at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:846)
 at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1296)
 at java.net.URL.openStream(URL.java:1035)
 at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
 at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source)
 at org.apache.xerces.impl.XMLEntityManager.startDTDEntity(Unknown Source)
 at org.apache.xerces.impl.XMLDTDScannerImpl.setInputSource(Unknown Source)
 at org.apache.xerces.impl.XMLDocumentScannerImpl$DTDDispatcher.dispatch(Unknown Source)
 at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
 at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
 at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
 at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
 at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
 at org.apache.commons.digester.Digester.parse(Digester.java:1548)
 at org.apache.struts.action.ActionServlet.parseModuleConfigFile(ActionServlet.java:1006)
 at org.apache.struts.action.ActionServlet.initModuleConfig(ActionServlet.java:955)
 at org.apache.struts.action.ActionServlet.init(ActionServlet.java:470)
 at javax.servlet.GenericServlet.init(GenericServlet.java:212)
 at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173)
 at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993)
 at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4149)
 at org.apache.catalina.core.StandardContext.start(StandardContext.java:4458)
 at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
 at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
 at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:526)
 at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:987)
 at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:909)
 at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:495)
 at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1206)
 at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:314)
 at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
 at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
 at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
 at org.apache.catalina.core.StandardService.start(StandardService.java:516)
 at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
 at org.apache.catalina.startup.Catalina.start(Catalina.java:583)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:601)
 at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
 at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
……

 

      经过调试,问题定位在struts-config.xml配置文件里的dtd校验:<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd">这里有问题。

 

      开发所在的虚拟机了确实是不能联网,怀疑是不是不能下载dtd文件的原因,于是就手动下载后,放到struts-config.xml同一目录下,重启tomcat后,再登陆,问题依然,无计可施,索性把:<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd">这一行给删了,重启登陆,这次却意外的成功了。

      这到底是什么原因呢,引入的包绝对没动过,代码也不会有问题,因为之前一直都能运行,删除了那句校验后也能正常运行,这句校验语句到底是怎么回事?没有头绪。

 

 

 

 

 

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐