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

时间:2021-11-16 16:58:32

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>

2 个解决方案

#1


22  

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/xml instead of text/html and 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.

当客户端(webbrowser)由于某种原因将HTTP响应内容解释为text / xml而不是text / html并且解析的XML树没有任何XML样式表时,您将在客户端获得此错误。换句话说,由于HTTP响应内容类型错误或缺失,Web浏览器错误地将检索到的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 FacesServlet and 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 .xhtml file extension which is in your Firefox configuration apparently by default interpreted as text/xml.

对于具有.xhtml默认扩展名的JSF / Facelets文件,如果HTTP请求未调用FacesServlet,则可能会发生这种情况,因此无法解析Facelets文件并生成所需的HTML输出在XHTML源代码上。 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 FacesServlet as 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.jsf instead 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(如浏览器的地址栏中所示)与在webapp的web.xml中注册的FacesServlet的 匹配,以便调用它并能够生成所需的URL基于XHTML源代码的HTML输出。如果它是例如* .jsf,则需要通过/some.jsf而不是/some.xhtml打开页面。或者,您也可以将 更改为* .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内容。

#2


-1  

If you are using Eclipse there are plenty of Simple way to create war .. 1- Right Click on your project 2- Then choose Export->WAR File 3- It will show you Web Project Name and now give destination where you will want to save war file. 4- If you want to export source file check Export Source File option. 5-Then click on finish .

如果您正在使用Eclipse,那么有很多简单的方法来创建战争.1-右键单击您的项目2-然后选择Export-> WAR File 3-它将显示Web项目名称,现在将目标提供给您想要的目标保存战争档案。 4-如果要导出源文件,请选中“导出源文件”选项。 5-然后点击完成。

Thats it you will get your project war file and copy this war and put in Tomcat Webapps directory and start the Server.

多数民众赞成你将得到你的项目战争文件并复制这个战争并放入Tomcat Webapps目录并启动服务器。

#1


22  

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/xml instead of text/html and 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.

当客户端(webbrowser)由于某种原因将HTTP响应内容解释为text / xml而不是text / html并且解析的XML树没有任何XML样式表时,您将在客户端获得此错误。换句话说,由于HTTP响应内容类型错误或缺失,Web浏览器错误地将检索到的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 FacesServlet and 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 .xhtml file extension which is in your Firefox configuration apparently by default interpreted as text/xml.

对于具有.xhtml默认扩展名的JSF / Facelets文件,如果HTTP请求未调用FacesServlet,则可能会发生这种情况,因此无法解析Facelets文件并生成所需的HTML输出在XHTML源代码上。 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 FacesServlet as 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.jsf instead 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(如浏览器的地址栏中所示)与在webapp的web.xml中注册的FacesServlet的 匹配,以便调用它并能够生成所需的URL基于XHTML源代码的HTML输出。如果它是例如* .jsf,则需要通过/some.jsf而不是/some.xhtml打开页面。或者,您也可以将 更改为* .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内容。

#2


-1  

If you are using Eclipse there are plenty of Simple way to create war .. 1- Right Click on your project 2- Then choose Export->WAR File 3- It will show you Web Project Name and now give destination where you will want to save war file. 4- If you want to export source file check Export Source File option. 5-Then click on finish .

如果您正在使用Eclipse,那么有很多简单的方法来创建战争.1-右键单击您的项目2-然后选择Export-> WAR File 3-它将显示Web项目名称,现在将目标提供给您想要的目标保存战争档案。 4-如果要导出源文件,请选中“导出源文件”选项。 5-然后点击完成。

Thats it you will get your project war file and copy this war and put in Tomcat Webapps directory and start the Server.

多数民众赞成你将得到你的项目战争文件并复制这个战争并放入Tomcat Webapps目录并启动服务器。