I tried to follow this post by integrating it to the Spring MVC
which result me to these codes:
Controller:
@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 page:
<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>
But for some reason the ${pageContext.request.contextPath}
causing an error:
I tried to click the link that accessing the controller it just displaying the PDF file in the whole page which is not my goal. What I want to do is display the PDF in the object tag