Liferay Portal을 통해 브라우저에 PDF (직접 디스플레이) 파일을 보낼 수있는 방법을 찾고있었습니다. 많은 솔루션을 발견했습니다. 가장 인기있는 솔루션은 Servlet을 작성하여 작업을 수행하는 것입니다. JSR 286 스펙에서 포틀릿 리소스 서비스에 대해 읽었습니다. 누군가 Spring 3.0 포틀릿 MVC에 대해 자세히 설명해 주실 수 있습니까?Spring Portlet MVC Architecture - Liferay 6.0.6
<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>
그리고 서블릿 구성되어 있습니다 : 나는 서블릿 <에 아무것도 찾을 수 없습니다
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;
} finally {
if (bis != null)
{
bis.close();
}
if (bos != null)
{
bos.flush();
bos.close();
}
}
}
스프링 컨트롤러에서 요청 매핑 URL을 매핑하는 실제 방법은 portlet : resourceURL 태그의 'id'속성을 사용하고 컨트롤러의 @ResourceMapping 속성 . 메서드에 URL을 매핑해야합니다. 그러나 만약 당신이 직접 비교하고 매핑하는 것을 꺼리지 않는다면, 위의 방법은 잘 동작합니다. –