【问题标题】:java.io.IOException: Server returned HTTP response code: 503 for URL: http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtdjava.io.IOException:服务器返回 HTTP 响应代码:503 用于 URL:http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
【发布时间】:2010-03-23 18:27:39
【问题描述】:

在以下代码中:

private Document transformDoc(Source source) throws TransformerException, IOException {
    TransformerFactory factory = TransformerFactory.newInstance();

    Transformer transformer =
            factory.newTransformer(new StreamSource(xsltResource.getInputStream()));
    JDOMResult result = new JDOMResult();
    transformer.transform(source, result);
    return result.getDocument();
}

我得到了这个例外:

java.io.IOException: Server returned HTTP response code: 503 for URL: http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd

我通过 xsl 翻译的 XHTML 是:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
  <title>Terms and Conditions</title>
</head>
<body>
  <div>Test Content</div>
</body>
</html>

如何阻止 xalan 变压器给家里打电话?

【问题讨论】:

    标签: java xhtml xslt xalan


    【解决方案1】:

    要么在解析器中禁用 DTD 解析(特定于解析器),要么设置一个空的实体解析器。

    复制自http://www.jdom.org/docs/faq.html#a0350:

    public class NoOpEntityResolver implements EntityResolver {
      public InputSource resolveEntity(String publicId, String systemId) {
        return new InputSource(new StringBufferInputStream(""));
      }
    }
    
    // Then in the builder...
    
    builder.setEntityResolver(new NoOpEntityResolver());
    

    【讨论】:

      【解决方案2】:

      This post from the Xalan-J mailing list 建议“正确的方法”是您自己配置底层Source/Reader 以禁用验证。

      【讨论】:

      • 您需要以下内容才能做到 100% 正确,但该邮件列表链接最有帮助! SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setNamespaceAware(true); spf.setValidating(false); // 关闭验证 spf.setFeature("apache.org/xml/features/nonvalidating/load-external-dtd", false); XMLReader rdr = spf.newSAXParser().getXMLReader();
      猜你喜欢
      • 2012-04-18
      • 2011-02-03
      • 1970-01-01
      • 2014-02-22
      • 2023-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      相关资源
      最近更新 更多