在网页中嵌入PDF

时间:2013-10-30 12:12:57

标签: spring jsp pdf

我尝试将此post集成到Spring MVC,并将其转化为以下代码:

控制器:

@RequestMapping( value = "/assign/{id}" )
public String getModule( @PathVariable( "id" )
int fileId, Model model, HttpServletResponse response )
{
    model.addAttribute( "id", fileId );
    File test = new File( "C:\\resource\\pdf\\Another Sample.pdf" );
    response.setHeader( "Content-Type", "application/pdf" );
    response.setHeader( "Content-Length", String.valueOf( test.length() ) );
    response.setHeader( "Content-Disposition", "inline; filename=\"Another Sample.pdf\"" );
    try
    {
        Files.copy( test.toPath(), response.getOutputStream() );
    }
    catch( IOException e )
    {

        e.printStackTrace();
    }
    return "redirect:../assign.do";
}

JSP页面:

<object data="${pageContext.request.contextPath}/Another Sample.pdf" type="application/pdf" width="100%" height="100%">
     <p>Download Missing plug-in <a href="http://get.adobe.com/reader/" class="btn btn-link">here</a> </p>
</object>

但由于某种原因${pageContext.request.contextPath}导致错误:

enter image description here

我试图点击访问控制器的链接,只显示整个页面中的PDF文件,这不是我的目标。 我想要做的是在对象标签中显示PDF

0 个答案:

没有答案