本文介绍了使用f:view覆盖默认的contentType-缺点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JSF 2.0应用程序中使用了许多jQuery插件,但并非所有插件都生成可以成功通过webkit浏览器严格XHTML检查的HTML.因此,解决方案是实际进入插件的代码并对其进行更正,以使其生成有效的HTML,这本身是一个非常耗时的过程,或者将生成的HTML的内容包装在<f:view contentType="text/html">中.后者非常简单,并且可以正常工作.使用<f:view>以这种方式覆盖内容类型有什么弊端吗?

I use a lot of jQuery plugins in my JSF 2.0 application and not all of them generate HTML which can successfully pass through the strict XHTML checks of webkit browsers. So the solution is to actually get into the plugin's code and correct it so that it generates a valid HTML, which is a very time consuming process in itself, or, wrap the contents of generated HTML in <f:view contentType="text/html">. The latter is quite straight forward and it works.Are there any cons of using <f:view> to override the content type in such a manner?

推荐答案

JSF默认使用 Accept 标头,由网络浏览器发送.如果URL匹配*.xhtml,则在某些浏览器中通常以application/xhtml+xml结尾,而在其他浏览器中通常以text/html结尾.您可以毫无问题地将其强制为text/html,无论如何,大多数浏览器都将XHTML视为HTML.但是,强制使用application/xhtml+xml是另一回事:MSIE不以任何方式支持它.

JSF defaults to the closest media type in the Accept header as is been sent by the webbrowser. If the URL matches *.xhtml, then it will usually end up to be application/xhtml+xml in some browsers and text/html in other browsers. You can without any problems force it to be text/html, most browsers treat XHTML as HTML anyway. Forcing to application/xhtml+xml is however a different story: MSIE doesn't support it in any way.

  • IE's XHTML Compatibility
  • Internet Explorer wants to download the webpage of GuessNumber example application instead of displaying it
  • Is it possible to use JSF+Facelets with HTML 4/5?

这篇关于使用f:view覆盖默认的contentType-缺点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 10:43