2017-03-15 4 views
0

私はSpring MVCで作業しています。私はpdfをダウンロードしたいと思います。私は、「あなたが.....開いた場合、または保存しますか?」と表示したくない、次のダイアログウィンドウに春のMVC質問なしでファイルをダウンロード

enter image description here

を表示したくありません。 ファイルを直接画面に表示したい。

@RequestMapping(value="/visualizarmanual", method=RequestMethod.POST) 
    public HttpEntity<byte[]> descargarManual(@RequestParam("directorioDocumentacion") String directorioDocumentacion, 
      @RequestParam("nombreDocumento") String nombreDocumentoP,HttpServletRequest request, 
      HttpServletResponse resp) throws IOException, Exception { 
     // convert JSON to Employee 
     logger.info("DocumentacionController descargarManual principio "); 
     String nombreDocumento = "springEcalcpAdmin.properties"; 
     logger.info("DocumentacionController descargarManual nombreDocumento "+nombreDocumento); 

     HttpHeaders headers = new HttpHeaders(); 
     headers.setContentType(MediaType.parseMediaType("application/plain")); 

     headers.setContentDispositionFormData(nombreDocumento, nombreDocumento); 
     byte[] documentBody = crearFichero(request,nombreDocumento); 
     headers.setCacheControl("must-revalidate, post-check=0, pre-check=0"); 
     ResponseEntity<byte[]> response = new ResponseEntity<byte[]>(documentBody, headers, HttpStatus.OK); 
     return response; 
    } 

確認せずにファイルをダウンロードする方法はあります:

は、私は次の方法を書きましたか?

答えて

0

これはコンテンツの処理で処理できます。

ウェブページのようにファイルを開く場合は、インラインで指定する必要があります。

Content-Disposition: inline 

ファイルをダウンロードする場合は、添付ファイルとして指定する必要があります。ダウンロードしたファイルの名前を指定する場合はfilenameを使用できますが、これは必須ではありません。

Content-Disposition: attachment; filename="filename.jpg" 

あなたは

https://developer.mozilla.org/es/docs/Web/HTTP/Headers/Content-Disposition

ここで多くを見ることができます