Java 如何在JSF面板中呈现mimetype为“text/html”或“text/plain”的流文件

Java 如何在JSF面板中呈现mimetype为“text/html”或“text/plain”的流文件,java,jsf,servlets,jsf-2,primefaces,Java,Jsf,Servlets,Jsf 2,Primefaces,我正在研究JSF2.2和Primefaces 5.1,在我的项目中有一个更新响应输出流的servlet,我在JSF中调用该servlet来呈现PDF,如下所示 <c:when test="#{documentBean.docType == 'application/pdf'}"> <p:media value="/filePreview?id=#{searchBean.selectedID}" player="pdf" width="100%" height="300"

我正在研究JSF2.2和Primefaces 5.1,在我的项目中有一个更新响应输出流的servlet,我在JSF中调用该servlet来呈现PDF,如下所示

<c:when test="#{documentBean.docType == 'application/pdf'}">
    <p:media value="/filePreview?id=#{searchBean.selectedID}" player="pdf" width="100%" height="300"/>          
</c:when>
这对我来说很好,但我有另一个mimetype文件,比如text/plain和text/html,因为这个标签不适用于所有浏览器


有没有办法在JSF 2.2或primefaces中呈现这种类型的文件?

java for string您需要使用equal

试试下面的代码

<c:when test="#{documentBean.docType eq 'application/pdf'}">
    <p:media value="/filePreview?id=#{searchBean.selectedID}" player="pdf" width="100%" height="300"/>          
</c:when>


我已经解决了下面这类对我有用的问题,我希望这也能帮助其他人

注意:ifram也适用于文本/普通和其他图像类型

<c:when test="#{documentBean.docType == 'text/html'}">
    <iframe src="/filePreview?id=#{searchBean.selectedID}" width="100%" height="500"></iframe>              
</c:when> 
在我的代码中运行良好,我想知道如何重新排序其他不是PDF而是文本或html的文件
<c:when test="#{documentBean.docType == 'text/html'}">
    <iframe src="/filePreview?id=#{searchBean.selectedID}" width="100%" height="500"></iframe>              
</c:when>