我正在寻找一种通过Liferay Portal将PDF(直接显示)文件发送到浏览器的方法.找到了许多解决方案 - 最受欢迎的解决方案是编写一个可以完成工作的Servlet.我已经阅读了JSR 286规范中关于Portlet资源服务的内容,有人可以为Spring 3.0 Portlet MVC详细说明吗?
<servlet>
<display-name>DownloadServlet</display-name>
<servlet-name>DownloadServlet</servlet-name>
<servlet-class>com.liferay.portal.pdf.DownloadServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DownloadServlet</servlet-name>
<url-pattern>/DownloadServlet/*</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)
Servlet包括:
private void downloadServlet(HttpServletRequest req,
HttpServletResponse resp) throws ServletException, IOException {
logger.debug(" downloadServlet :: ");
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
ServletOutputStream op = null;
try {
//Something
pdfContentVO=//getpdf VO here
String filename = "PDFFILE_"+pdfNumber+".pdf";
op = resp.getOutputStream();
resp.setContentType("application/pdf");
resp.setHeader("Content-Disposition", "attachment; filename="
+ filename);
resp.setContentLength(pdfContentVO.getPdfData().length);
System.out.println("pdfcontent"+pdfContentVO.getPdfData());
op.write(pdfContentVO.getPdfData());
op.flush();
op.close();
} catch(final IOException e) {
System.out.println ( "IOException." );
throw e;
} …Run Code Online (Sandbox Code Playgroud)