Domanda

Sono fermamente la necessità di sovrascrivere JSF 2.0 Content-Type di intestazione. Default è

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

Ma ho bisogno

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

Grazie.

È stato utile?

Soluzione

Come su

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

Altri suggerimenti

Utilizza la destra doctype .

<!DOCTYPE html>

Niente di più. Inoltre, non mettere dichiarazione <?xml?> in alto. Ecco un modello di minima:

<!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>

E 'il doctype HTML5. E 'pienamente compatibile con XHTML 1.x markup e aggiunge ulteriori vantaggi.

Il seguente approccio funziona in tutti i browser:

Scrivi una 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");

        }
    }

e registrarlo in faccia-context.xml:

<lifecycle>
        <phase-listener>com.mycompnay.listener.ContentTypePhaseListener </phase-listener>
    </lifecycle>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top