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