clicking on a link for a PDF file just opens a blank page on the browser. If I save the file to a directory and then open it, the file opens without any problem. The exact code works correct outside of Spring framework using a plain servet. Any ideas what needs to change to make it work in Spring?
Here is the code:
Code:public ModelAndView binitemHandler(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String repId = RequestUtils.getStringParameter(request, "RepID", ""); BinaryItem binitem = null; ModelAndView mav = null; String ext = ""; binitem = (BinaryItem) myFacade.getBinItem(repId); fileName = binitem.getFilename(); logger.debug("Filename is: "+fileName); if (fileName != null) { int dot = fileName.lastIndexOf('.'); ext = (dot > 0) ? fileName.substring(dot) : "txt"; logger.debug("Extension is: "+ext); } response.setContentType(mapFileToMime(ext)); logger.debug("Extension is setContentType: "+mapFileToMime(ext)); response.setHeader("Content-disposition", "inline; filename=" + fileName); FileCopyUtils.copy(binitem.getBytes(), response.getOutputStream()); return mav; }
Code:private String mapFileToMime(String type) { if (type.equalsIgnoreCase(".gif")) { return "image/gif"; } else if (type.equalsIgnoreCase(".jpg")) { return "image/jpg"; } else if (type.equalsIgnoreCase(".jpeg")) { return "image/jpg"; } else if (type.equalsIgnoreCase(".doc")) { return "application/msword"; } else if (type.equalsIgnoreCase(".123")) { return "application/vnd.lotus-1-2-3"; } else if (type.equalsIgnoreCase(".prz")) { return "application/vnd.lotus-freelance"; } else if (type.equalsIgnoreCase(".lwp")) { return "application/vnd.lotus-wordpro"; } else if (type.equalsIgnoreCase(".xls")) { return "application/vnd.ms-excel"; } else if (type.equalsIgnoreCase(".ppt")) { return "application/vnd.ms-powerpoint"; } else if (type.equalsIgnoreCase(".vsd")) { return "application/vnd.visio"; } else if (type.equalsIgnoreCase(".pdf")) { return "application/pdf"; } else if (type.equalsIgnoreCase(".wk4")) { return "application/vnd.lotus-1-2-3"; } return "application/octet-stream"; }


Reply With Quote