我強烈需要覆蓋JSF 2.0 Content-Type標題。默認情況下它是JSF,覆蓋HTTP標頭
Content-Type:application/xhtml+xml; charset=UTF-8
但我需要
Content-Type:text/html; charset=UTF-8
感謝。
我強烈需要覆蓋JSF 2.0 Content-Type標題。默認情況下它是JSF,覆蓋HTTP標頭
Content-Type:application/xhtml+xml; charset=UTF-8
但我需要
Content-Type:text/html; charset=UTF-8
感謝。
如何
<f:view contentType="text/html" />
<!DOCTYPE html>
沒有更多。頂部也不要放<?xml?>
聲明。這是最小模板:
<!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>
這是HTML5的文檔類型。它與XHTML 1.x標記完全兼容,並增加了更多優勢。
刪除了我不清楚的答案,並感謝您清除它。 – 2010-09-27 13:58:03
以下方法適用於所有的瀏覽器:
寫的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");
}
}
,並在faces-context.xml中進行註冊:
<lifecycle>
<phase-listener>com.mycompnay.listener.ContentTypePhaseListener </phase-listener>
</lifecycle>
該解決方案是必要的工作與舊版本的iPhone和iPad。似乎稍後的瀏覽器會覆蓋默認的Content-Type並進行最佳猜測。但是較老的瀏覽器都在考慮Content-Type標題並期待標題。很簡單的解決方案。 – JeffJak 2012-12-13 22:38:52