To follow up to this post I change the code to this:
@RequestMapping( value = "/{prePath:^tutor$|^admin$}/module/{file_id}" )
public void getModule( @PathVariable( "file_id" )
int fileId, Model model, HttpServletResponse response, HttpServletRequest request )
{
model.addAttribute( "id", fileId );
File test = new File( "C:\\resource\\pdf\\test.pdf" );
response.setHeader( "Content-Type", "application/pdf" );
response.setHeader( "Content-Length", String.valueOf( test.length() ) );
response.setHeader( "Content-Disposition", "inline; filename=\"test.pdf\"" );
System.out.println( test.toPath() );
try
{
Files.copy( test.toPath(), response.getOutputStream() );
}
catch( IOException e )
{
e.printStackTrace();
}
}
And finally able to display PDF in the webpage. The URL is accessed by:
<a href="../admin/module/${ file_id }.do?test" >Spring Tutorial</a>
But the PDF file is displaying on the whole page. My PDF is from my local I want to display it with just a portion of webpage. Maybe a <div>
or anything that suit the approach best. Any thoughts of how can I do this?