多个pdf在浏览器1中显示1

时间:2014-04-10 10:47:27

标签: java javascript spring spring-mvc iframe

我有一个页面,我将显示用户上传的文件列表(pdf文件)。 现在,我想要实现的是在这个列表表格下一次显示这些pdf文件。

我可以做的第一部分...我将调用我的控制器方法并获取列表,然后我将在我的jsp页面中填充表格。 第二部分我不确定,我应该如何处理呢?

返回列表的第一个方法:

@RequestMapping("/tasks/viewDocuments.do")
public ModelAndView viewDocuments(@RequestParam("reqId") Integer reqId) {
    try{
        log.info("inside viewDocuments, reqId: "+reqId);

        //get the file details and show the list on page. 

        return new ModelAndView("tasks/viewDocumentsHTML" , "wrapper" ,"" );
    }catch (Exception e) {
        log.info("error in viewDocuments: "+e);
        return new ModelAndView ("xstream", "response","system.error");
    }
}

返回pdf的第二种方法:

@RequestMapping("/tasks/showDocumentsInIframe.do")
public void showDocumentsInIframe(HttpServletRequest request, HttpServletResponse response) {
    try{
        log.info("inside showDocumentsInIframe");
        ServletOutputStream out = response.getOutputStream();

        String fileURL = "http://www.saronicferries.gr/content/pdfFiles/sample.pdf";
        URL url = new URL(fileURL);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        log.debug("length: "+connection.getContentLength());
        BufferedInputStream bufferedInputStream = new BufferedInputStream(connection.getInputStream());
        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(out);

        int bytesRead = 0;
        byte[] buffer = new byte[1024];

        response.setContentLength(connection.getContentLength());
        response.setContentType("application/pdf");
        response.setHeader("Content-Disposition", "inline; filename=help.pdf");
        response.setHeader("Cache-Control", "cache, must-revalidate");
        response.setHeader("Pragma", "public");

        while ((bytesRead = bufferedInputStream.read(buffer)) != -1) {
            bufferedOutputStream.write(buffer, 0, bytesRead);
        }
        log.info("finishing showDocumentsInIframe");
        bufferedOutputStream.flush();

    }catch (Exception e) {
        log.info("error in showDocumentsInIframe: "+e);
        //return new ModelAndView ("xstream", "response","system.error");
    }
}

jsp页面:

    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
    <%@ taglib prefix="sec"
    uri="http://www.springframework.org/security/tags"%>
<link type="text/css" rel="stylesheet"
    href="<c:url value="/public/css/jquery.css"/>"></link>
<link type="text/css" rel="stylesheet"
    href="<c:url value="/public/css/portal_style.css"/>"></link>

<script type="text/javascript"
    src="<c:url value="/public/js/jquery/jquery-1.3.min.js"/>"></script>

<form>
    <table width="100%" cellspacing="0" cellpadding="0" border="1"
        style="display: inline;">
        <tr class="portlet-table-header">
            <td align="left">Sr. No.:</td>
            <td align="left">File Name:</td>
            <td align="left"></td>
            <td align="left"></td>
        </tr>
        <c:forEach var="workList" items="${wrapper.voList}">
            <tr class="portlet-table-body">
                <td>${workList.srNo}</td>
                <td>${workList.fileName}</td>
                <td><a href="javascript:taskDetails.viewDocuments()">View</a></td>
                <td><a href="javascript:taskDetails.removeDocuments()">Remove</a></td>
            </tr>
        </c:forEach>
    </table>
</form>
<br><br>
<embed id="pdfViewer" src="/tasks/showDocumentsInIframe.do" width="500" height="375" />

对第二种方法的调用永远不会起作用。 我在这做错了什么?

0 个答案:

没有答案