With an XML file that declares a DOCTYPE, take the struts.xml file for instance:

Does the Java SAX processing actually go get the dtd from the provided URL?

有帮助吗?

解决方案

Many (most) implementations will, even though technically, if I remember correctly, the location is meant to be interpreted as a URI, not URL.

If you want to be sure to resolve it locally, take a look at the EntityResolver interface.

其他提示

Based on the Xerces documentation, the parser may try to download the file from the internet when validation is turned on. But I really think this can change from parser to parser, because the library may decide to use a local cache, a proxy server or whatever.

You can modify the struts.xml to load the DTD file from the struts2 core jar from the classpath rather than loading it from internet

FROM

<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts 
Configuration//EN" 
"http://struts.apache.org/dtds/struts-2.0.dtd"> 

CHANGE TO

<!DOCTYPE struts SYSTEM "struts-2.0.dtd">

now the sax parser loaded the struts-2.0.dtd file from the /src folder where i placed.

Also this is my modified hibernate configuration file which worked a little differently. It loaded the dtd file directly from the JAR, did not have to physically place it in the src folder

<!DOCTYPE hibernate-configuration SYSTEM "classpath://org/hibernate/hibernate-configuration-3.0.dtd">
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top