4

How can I make JSF send http header
Content-Type: application/xhtml+xml;charset=UTF-8 instead of current
Content-Type: text/html;charset=UTF-8?

Adding following snippet in web.xml had no effect.

<mime-mapping>
    <extension>xhtml</extension>
    <mime-type>application/xhtml+xml</mime-type>
</mime-mapping>

My sample file webapp/sample.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
<f:view>
    <h:outputLabel value="Hello, world"/>
</f:view>
</html>

Environment:
JSF 2.2, WildFly 8.2

czerny
  • 11,433
  • 12
  • 57
  • 80
  • Because `application/xhtml+xml` is proper MIME type of XHTML5 http://www.w3.org/TR/html5/introduction.html#html-vs-xhtml – czerny Mar 07 '15 at 00:32
  • Yes, I know, but did you read the answer in the link I posted regarding IE? – Kukeltje Mar 07 '15 at 00:53
  • Yes I did, thanks for that one. It still feels good to know how to change that setting, not just being glad for reasonable defaults. – czerny Mar 07 '15 at 01:22

1 Answers1

5

You can set it in <f:view> as below:

<f:view contentType="application/xhtml+xml">

However, this is the wrong value for HTML. JSF/XHTML generates HTML output which should really have text/html content type. Explanation can be found in the answer to When to use f:view and f:subview, particularly in the "See also" links in that answer.

Community
  • 1
  • 1
Kukeltje
  • 11,924
  • 4
  • 19
  • 44