I can´t open a .pdf in my browser by Java

后端 未结 5 1170
悲&欢浪女
悲&欢浪女 2021-01-16 13:13

I´m trying to open a pdf that I have created using iText library in my browser, but it fails. This is the code I´m using to send to browser

    File file = n         


        
相关标签:
5条回答
  • 2021-01-16 13:33

    You specify the mimetype as application/text, when it should be application/pdf.

    0 讨论(0)
  • 2021-01-16 13:46

    You should set the Header and ContentType before you write the data. And set the Content Type to application/pdf.

    0 讨论(0)
  • 2021-01-16 13:49

    Put the filename in double quote "

    response.setHeader("Content-Disposition","attachment; filename=\"" + attachmentName + "\"");
    
    0 讨论(0)
  • 2021-01-16 13:49

    Android Default Browser requires GET Request. It does not understand POST Request and hence cannot download the attachment. You can send a GET request as by sending GET request, it resolved my problem. Android browser generates a GET request on its own and sends it back to server. The response received after second request will be considered final by the browser even if GET request is sent on first time by the servlet.

    0 讨论(0)
  • 2021-01-16 13:54

    change

     response.setContentType("application/text");
    

    to

    response.setContentType("application/pdf");
    

    and if you want your pdf to open in browser then make following change

    response.setHeader("Content-Disposition",  "inline");
    
    0 讨论(0)
提交回复
热议问题