我正在jsp页面中开发一个jsp页面我有这么多文件(pdf,images ..)现在我想在jsp页面中打开这些文件。
现在我只能在jsp中打开pdf文件,但我想在jsp页面中打开所有类型的文件
<object data="myfile.pdf" type="application/pdf" width="100%" height="100%">
Alternative text - include a link <a href="myfile.pdf">to the PDF!</a>
</object>
任何身体都可以帮助我....
答案 0 :(得分:1)
这是你在寻找什么? 如果是,您可以使用Servlet:)
@WebServlet("/myfile.pdf.pdf")
public class PdfServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
File file = new File("C:\\User\\myfile.pdf");
response.setHeader("Content-Type", getServletContext().getMimeType(file.getName()));
response.setHeader("Content-Length", String.valueOf(file.length()));
response.setHeader("Content-Disposition", "inline; filename=\"myfile.pdf\"");
Files.copy(file.toPath(), response.getOutputStream());
}
}
JSP
<object data="${pageContext.request.contextPath}/myfile.pdf.pdf"
type="application/pdf" width="100%" height="100%">
<a href="${pageContext.request.contextPath}/myfile.pdf.pdf">Download PDF</a> </object>