打开 XML 页面显示“此 XML 文件似乎没有与之关联的任何样式信息。”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14804452/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 13:52:55  来源:igfitidea点击:

Opening XML page shows "This XML file does not appear to have any style information associated with it."

xmleclipsejsffacelets

提问by Krzysiek

I'm trying to run my Eclipse JSF project on Apache Tomcat on other computer. I created a WAR file with this tutorial. However, when I deploy the WAR and open the Facelet page in Firefox, I'm getting only the following error message:

我正在尝试在其他计算机上的 Apache Tomcat 上运行我的 Eclipse JSF 项目。我使用本教程创建了一个 WAR 文件。但是,当我部署 WAR 并在 Firefox 中打开 Facelet 页面时,我只收到以下错误消息:

This XML file does not appear to have any style information associated with it. The document tree is shown below.

此 XML 文件似乎没有任何与之关联的样式信息。文档树如下所示。

This my first time when I try run my JSF app without Eclipse. How is this caused and how can I solve it?

这是我第一次尝试在没有 Eclipse 的情况下运行我的 JSF 应用程序。这是怎么引起的,我该如何解决?

I'm actually trying to open the following Facelet page:

我实际上是在尝试打开以下 Facelet 页面:

<?xml version="1.0" encoding="UTF-8"?>
<ui:composition template="/WEB-INF/templates/template_a.xhtml"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets">
    <ui:define name="title">
        tytol
    </ui:define>
</ui:composition>

回答by BalusC

This XML file does not appear to have any style information associated with it. The document tree is shown below.

此 XML 文件似乎没有任何与之关联的样式信息。文档树如下所示。

You will get this error in the client side when the client (the webbrowser) for some reason interprets the HTTP response content as text/xmlinstead of text/htmland the parsed XML tree doesn't have any XML-stylesheet. In other words, the webbrowser incorrectly parsed the retrieved HTTP response content as XML instead of as HTML due to the wrong or missing HTTP response content type.

当客户端(网络浏览器)出于某种原因将 HTTP 响应内容解释为text/xml而不是text/html并且解析的 XML 树没有任何XML-stylesheet时,您将在客户端收到此错误。换句话说,由于错误或缺少 HTTP 响应内容类型,网络浏览器错误地将检索到的 HTTP 响应内容解析为 XML 而不是 HTML。

In case of JSF/Facelets files which have the default extension of .xhtml, that can in turn happen if the HTTP request hasn't invoked the FacesServletand thus it wasn't able to parse the Facelets file and generate the desired HTML output based on the XHTML source code. Firefox is then merely guessing the HTTP response content type based on the .xhtmlfile extension which is in your Firefox configuration apparently by default interpreted as text/xml.

对于具有默认扩展名的 JSF/Facelets 文件,.xhtml如果 HTTP 请求没有调用FacesServlet并且因此无法解析 Facelets 文件并基于 XHTML 生成所需的 HTML 输出,则可能会发生这种情况源代码。Firefox 然后只是根据.xhtml文件扩展名猜测 HTTP 响应内容类型,该文件扩展名在您的 Firefox 配置中显然默认解释为text/xml.

You need to make sure that the HTTP request URL, as you see in browser's address bar, matches the <url-pattern>of the FacesServletas registered in webapp's web.xml, so that it will be invoked and be able to generate the desired HTML output based on the XHTML source code. If it's for example *.jsf, then you need to open the page by /some.jsfinstead of /some.xhtml. Alternatively, you can also just change the <url-pattern>to *.xhtml. This way you never need to fiddle with virtual URLs.

你需要确保在HTTP请求的URL,只要在浏览器地址栏中看到,匹配<url-pattern>FacesServlet为Web应用程序的注册web.xml,这样它会被调用,并且能够生成基于XHTML的源代码所需的HTML输出。例如*.jsf,如果是,那么您需要通过/some.jsf而不是来打开页面/some.xhtml。或者,您也可以将 更改<url-pattern>*.xhtml。这样你就永远不需要摆弄虚拟 URL。

See also:

也可以看看:



Note thus that you don't actually need a XML stylesheet. This all was just misinterpretation by the webbrowser while trying to do its best to make something presentable out of the retrieved HTTP response content. It should actually have retrieved the properly generated HTML output, Firefox surely knows precisely how to deal with HTML content.

请注意,您实际上并不需要 XML 样式表。这一切都只是网络浏览器的误解,同时试图尽最大努力从检索到的 HTTP 响应内容中做出一些可呈现的内容。它实际上应该检索到正确生成的 HTML 输出,Firefox 肯定知道如何处理 HTML 内容。