`

struts Caused by: no protocol dtd - Class: java.net.URL

阅读更多

情景:

项目使用了struts2框架,部署到tomcat中,而tomcat所在机器没有联网(处于公司安全方面的原因),所以启动tomcat时,报错:

tomcat Unable to load configuration. - Class: java.net.SocketInputStream

因为struts配置文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation/DTD Struts Configuration 2.1.7//EN"
        "http://struts.apache.org/dtds/struts-2.3.dtd">

如上所示,它会 去http://struts.apache.org/dtds/struts-2.3.dtd下载dtd文件,但是没有联网,所以就报上述错误(标红的)了。

 

为了解决这个问题,就使用了本地的dtd文件,范例:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation/DTD Struts Configuration 2.1.7//EN"
        "./com/tdr/mbs/endpoint/dtd/struts-2.3.dtd">

 

后来项目部署到其他tomcat时,报错:

Caused by: no protocol dtd - Class: java.net.URL

详细报错信息:

 

Unable to load configuration. - Class: java.net.URL
File: URL.java
Method: <init>
Line: 567 - java/net/URL.java:567:-1
	at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:69)
	at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:390)
	at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:437)
	at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:74)
	at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:51)
	at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:295)
	at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:422)
	at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:115)
	at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3838)
	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4488)
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
	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:593)
	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)
Caused by: Unable to load file:/D:/个人资料/eclipse/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/endpoint/WEB-INF/classes/struts.xml - Class: java.net.URL
File: URL.java
Method: <init>
Line: 567 - java/net/URL.java:567:-1
	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadConfigurationFiles(XmlConfigurationProvider.java:954)
	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadDocuments(XmlConfigurationProvider.java:163)
	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.init(XmlConfigurationProvider.java:130)
	at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:209)
	at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:66)
	... 22 more
Caused by: no protocol: ./com/a//endpoint/dtd/struts-2.3.dtd - Class: java.net.URL
File: URL.java
Method: <init>
Line: 567 - java/net/URL.java:567:-1
	at com.opensymphony.xwork2.util.DomHelper.parse(DomHelper.java:115)
	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadConfigurationFiles(XmlConfigurationProvider.java:949)
	... 26 more
Caused by: java.net.MalformedURLException: no protocol: ./com/a//endpoint/dtd/struts-2.3.dtd
	at java.net.URL.<init>(URL.java:567)
	at java.net.URL.<init>(URL.java:464)
	at java.net.URL.<init>(URL.java:413)
	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.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
	at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
	at com.opensymphony.xwork2.util.DomHelper.parse(DomHelper.java:113)
	... 27 more

 

上网查了半天,发现这是tomcat的一个bug。

出现的场景:

 

<!--[if !supportLists]-->(1)   <!--[endif]-->tomcat 的安装目录中有中文字符;

struts.xml中没有使用网络上的dtd文件,而是使用的本地的dtd文件

 

问题原因tomcat 安装目录中有中文字符。

 

解决方法:tomcat的安装目录拷贝到无中文字符的路径中。

 

 后记:后来我使用eclipse运行项目,也报相同的错误,因为我eclipse的工作空间(workspace)是:

D:\个人资料\eclipse\workspace

我的eclipse的工作空间的路径中包含中文字符。

报错信息:

Caused by: Unable to load file:/D:/个人资料/eclipse/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/endpoint/WEB-INF/classes/struts.xml - Class: java.net.URL

File: URL.java

Method: <init>

Line: 567 - java/net/URL.java:567:-1

 

也就是说eclipse把项目部署到了 D:/个人资料/eclipse/workspace/.metadata/ 中

解决方法:修改eclipse的工作区间(没办法了,一定要保证项目部署的路径中没有中文字符

0
2
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics