java - how to view pdf file in jsp -
i want view pdf file view dynamically in pop window using java.while clicking file link open pdf file pop window don't allow down load option please me give example in java.i need need java code using action jsp
file f= new file(file); if(f.exists()){ servletoutputstream op= response.getoutputstream(); response.reset(); if(check==1){ response.setcontenttype("application/pdf"); }else{ response.setcontenttype(content); } // response.setheader("content-disposition","attachment; filename=" +filename); byte[] buf = new byte[4096]; int length; datainputstream in = new datainputstream(new fileinputstream(f)); while ((in != null) && ((length = in.read(buf)) != -1)){ op.write(buf,0,length); } in.close(); op.flush(); op.close(); }
to open local file need use file scheme in url
as path windows path e:/files/it/cat1/cat1notification.pdf, link's href needs file:/// added before jsp's <%=path%> variable, browser knows needs open local file on user's machine.
so link should this
">click here in browser resolve file:///e:/files/it/cat1/cat1notification.pdf
without file scheme browser assumes link relative webpage , tries resolve link making request webapp.
Comments
Post a Comment