Я включил JSP-страницу в Facelets, используя <ui:include>
. На странице JSP я могу получить PDF файл, но он отображает содержимое как обычный текст. Как это вызвано и как я могу его решить?
Страница JSP:
<html>
<%@page import="java.io.File"%>
<%@page import="java.io.*"%>
<body>
<%
response.reset();
File file = new File(
"D:\\TNWRD_Documents\\Knowladge_Base\\Financial_and_Administrative_powers.pdf");
response.setHeader("Content-Type", "application/pdf");
response.setHeader("Content-Disposition","inline;filename=Saba_PhBill.pdf");
response.setContentLength((int)file.length());
//OPen an input stream to the file and post the file contents thru the
//servlet output stream to the browser
FileInputStream in = new FileInputStream(file);
ServletOutputStream outs = response.getOutputStream();
response.setContentLength(in.available());
byte[] buf = new byte[8192];
int c=0;
try {
while ((c = in.read(buf, 0, buf.length)) > 0)
{
//System.out.println("size:"+c);
outs.write(buf, 0, c);
}
} catch (IOException ioe) {
ioe.printStackTrace(System.out);
} finally {
outs.flush();
outs.close();
in.close();
}
%>
</body>
</html>
Страница Facelets:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
xmlns:my="http://example.com/jsf"
>
<h:form>
<table width="100%" border="1">
<tr></tr>
<tr>
<td align="left" width="200px"><rich:tree id="fileTree" toggleType="ajax" var="item">
<rich:treeModelRecursiveAdaptor
roots="#{fileSystemBean.sourceRoots}" nodes="#{item.directories}">
<rich:treeNode>
#{item.shortPath}
</rich:treeNode>
<rich:treeModelAdaptor nodes="#{item.files}">
<rich:treeNode>
<a4j:commandLink value="#{item}"
action="#{TnwrdAction.downloadFile}" oncomplete="openFile();" render="fileTree"
immediate="true">
<f:setPropertyActionListener value="#{item}"
target="#{TnwrdBean.fileName}" />
</a4j:commandLink>
</rich:treeNode>
</rich:treeModelAdaptor>
</rich:treeModelRecursiveAdaptor>
</rich:tree></td>
<td >
<ui:insert name="Barrage" >
<my:include page="/WEB-INF/jsp/page.jsp" />
</ui:insert>
</td>
</tr>
</table>
</h:form>
</ui:composition>