文件已被移动 - 无法再次读取

时间:2015-02-03 08:53:57

标签: java jsp session spring-mvc

我将multipartfile存储到会话中,然后检索它以显示在表中。当我点击这个文件时,我收到了如下错误,

Servlet.service() for servlet [mvc-dispatcher] in context with path [/cims] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: File has been moved - cannot be read again] with root cause
java.lang.IllegalStateException: File has been moved - cannot be read again

这是我在控制器中的编码。我看到有人使用了getBinaryStream(),但在我的编码中,我无法称之为。请给我一些建议。谢谢。

@RequestMapping("/claim/transportation/download/{docId}")
    public String download(@PathVariable("docId") Integer docId, @ModelAttribute("dataHolderPrmClaimTransportationSession") DataHolderPrmClaimTransportationSession dataHolderPrmClaimTransportationSession,HttpServletResponse response){
        System.out.print(docId); System.out.println("DocID");
        try{
            response.setHeader("Content-Disposition", "inline;filename=\""+dataHolderPrmClaimTransportationSession.getUiPrmClaimTransportation().getTransportationRecordList().get(docId).getUploadFile().getOriginalFilename()+"\"");
            System.out.println("DocIDHeader");
            System.out.println(dataHolderPrmClaimTransportationSession.getUiPrmClaimTransportation().getTransportationRecordList().get(docId).getUploadFile().getOriginalFilename());
            OutputStream out=response.getOutputStream();
            System.out.println(out);
            response.setContentType("application/pdf");
            IOUtils.copy(dataHolderPrmClaimTransportationSession.getUiPrmClaimTransportation().getTransportationRecordList().get(docId).getUploadFile().getInputStream(),out);
            out.flush();
            out.close();
        }catch(IOException e)
        {
            logger.error(e.getMessage(),e);
        }

        return null;
    }

这是来自JSP。

<td id="selfTableAttachedFile"><a href="${pageContext.request.contextPath}/hra/prm/claim/transportation/download/${status.index}" target="_blank">${record.uploadFile.originalFilename }</a></td>

0 个答案:

没有答案