For some reasons, the application can render pdf in firefox but not in IE 7. I hope someone can tell me what I did wrong.
my url: http://<localhost>/<applicationName>/listDoc/viewpdf.htm?filename=test.pdf
My web.xmlCode:@RequestMapping(value="/listDoc/viewPdf",method=RequestMethod.GET) public @ResponseBody String streamPdf(HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "fileName", required = false) String fileName, SessionStatus status, ModelMap modelMap) throws Exception{ ServletOutputStream outstream = response.getOutputStream(); try{ logger.debug("Prepare to view pdf"); File tempDir = WebUtils.getTempDir(getServletContext()); String filePath = tempDir.getCanonicalPath()+"/"+fileName; File generatePdfFile = new File(filePath); if ((generatePdfFile.exists() && (generatePdfFile.canRead()))){ FileInputStream fileInputStream = new FileInputStream(generatePdfFile); response.setContentType("application/pdf"); response.setContentLength((int)generatePdfFile.length()); response.setHeader("Content-Disposition","inline; filename=test.pdf"); int readBytes=0; while((readBytes = fileInputStream.read()) != -1) { outstream.write(readBytes); } fileInputStream.close(); outstream.flush(); outstream.close(); } else { throw new Exception("Either document doesn't exist or can not be read"); } }catch(Exception e){ e.printStackTrace(); logger.error(e.getMessage(),e.fillInStackTrace()); throw new Exception ("Unable to stream pdf. Please contact your administrator"); }finally{ outstream.close(); outstream.flush(); } }
Thank for reading...Code:<servlet> <servlet-name>sampleapplication</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value> classpath:sampleapplication-web.xml </param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>sampleapplication</servlet-name> <url-pattern>*.htm</url-pattern> </servlet-mapping>


Reply With Quote