1. 程式人生 > >springmvc實現文件下載

springmvc實現文件下載

create OS mda RR ctu 亂碼問題 head http AD

//在springmvc中配置
            <bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
            <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/>
            <bean class="org.springframework.http.converter.BufferedImageHttpMessageConverter"/>
               <bean class
="org.springframework.http.converter.StringHttpMessageConverter" /> //controller寫法 @RequestMapping("download.do") public ResponseEntity<byte[]> download(HttpServletRequest request,HttpServletResponse response,String pictureFile) throws Exception{ File file=new File("F:\\upload\\image\\"+pictureFile); HttpHeaders headers
= new HttpHeaders(); pictureFile=new String(pictureFile.getBytes("UTF-8"),"iso-8859-1");//為了解決中文名稱亂碼問題 headers.setContentDispositionFormData("attachment", pictureFile); headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); return new ResponseEntity<byte
[]>(FileUtils.readFileToByteArray(file), headers, HttpStatus.CREATED); }

springmvc實現文件下載