2

我试图通过将其集成到这些代码中来关注这篇文章: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}导致错误:

在此处输入图像描述

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

4

0 回答 0