java - response.sendRedirect from a servlet redirects to a pdf which should get downloaded -


Can you please help me 1) How to open PDF in a new browser tab or window? (Or) 2) PDF should download directly to the local system.

I am using this,

  response.reset (); Response.setContentType ("application / octet stream"); Response.setHeader ("content-displacement", "attachment; filename = \" "+" zseriessection9.pdf "+" \ ""); Response.sendRedirect (referencepath + "/ zseriessection9.pdf");    

You should be below the parameters,

  ByteArrayOutputStream Baos = new byteOutStream (); Response.setContentType ("application / PDF"); Response.setHeader ("content-dispute", "attachment; file name = sample.pdf"); OutputStream OS = response.getOutputStream (); Baos.writeTo (OS); Os.flush (); Os.close ();   

This will show a browser window to open or saved pdf file. Moves the trick here and redirects it, because it creates a new request

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -