Pregunta

Creo firmemente que sobreescribir JSF 2.0 Content-Type cabecera. Por defecto es

Content-Type:application/xhtml+xml; charset=UTF-8

Pero necesito

Content-Type:text/html; charset=UTF-8

Gracias.

¿Fue útil?

Solución

¿Qué tal

<f:view contentType="text/html" />

Otros consejos

Utilice el derecho tipo de documento .

<!DOCTYPE html>

Nada más. Asimismo, no se ponga declaración <?xml?> en la parte superior. Aquí está una plantilla mínima:

<!DOCTYPE html>
<html 
    xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:ui="http://java.sun.com/jsf/facelets">
    <h:head>
        <title>Insert your title</title>
    </h:head>
    <h:body>
        <h1>Hello World</h1>
    </h:body>
</html>

Es el tipo de documento HTML 5. Es totalmente compatible con XHTML 1.x margen de beneficio y añade más ventajas.

El siguiente método funciona en todos los navegadores:

Escribir un PhaseListener:

  public class ContentTypePhaseListener implements PhaseListener {


        public PhaseId getPhaseId()
        {
            return PhaseId.RENDER_RESPONSE;
        }

        public void afterPhase(PhaseEvent event)
        {
        }

        public void beforePhase(PhaseEvent event)
        {
            FacesContext facesContext = event.getFacesContext();
            HttpServletResponse response = (HttpServletResponse) facesContext
                    .getExternalContext().getResponse();
            response.addHeader("Content-Type", "text/html; charset=UTF-8");

        }
    }

y registrarlo en caras-context.xml:

<lifecycle>
        <phase-listener>com.mycompnay.listener.ContentTypePhaseListener </phase-listener>
    </lifecycle>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top