Forum Moderators: mack

Message Too Old, No Replies

What does it mean to serve up a page?

I need my jsp to serve up a pdf file

         

pouneh

11:25 pm on Nov 13, 2003 (gmt 0)

10+ Year Member



Currently, my menu has a direct link to a pdf file, but
this means that a user could directly access this pdf file
whether or not they are logged in. I would like to have
a jsp which serves up the pdf and in the jsp I will do
a check to make sure the user is logged in. But I am not
sure how to "serve up" the page. Please help!

denisdekat

1:44 pm on Nov 14, 2003 (gmt 0)

10+ Year Member



Well I think in this case it means to allow the file to be downloaded. As in, if the user logs in, the JSP will "serve up" the PDF, meaning, return it to the client who called the JSP (the user).

I think that is what it could mean :)

HTH

garann

10:58 pm on Nov 14, 2003 (gmt 0)

10+ Year Member



I think you mean you want the JSP to open the PDF and send its contents to the client?

You need to change the type of response in your JSP to application/pdf. In the code of the JSP, you need to open the file and get a stream which will give you an array of data from that PDF. Your response object has a method that allows you to write a byte array to the client.

I think it would look like this. (Note that I haven't done Java for a while, so the syntax is probably pretty lousy.):


<%
...
response.setContentType("application/pdf");
FileInputStream fs = new FileInputStream("c:\allPDFs\mySecretPDF.pdf");
byte[] b = new byte[];
fs.read(b);
OutputStream os = response.getOutputStream();
os.write(b);
os.flush();
...
%>

Good luck!
g.

bcc1234

11:29 pm on Nov 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would not use a jsp page for it but would write a servlet so I could limit the output. It would suck to have an extra space or the next line char outside of the tags appear after your output.

You might also let the container do the reading and writing instead of doing it yourself.

Use request dispatcher's forward method.

pouneh

4:06 am on Nov 17, 2003 (gmt 0)

10+ Year Member



Thanks everyone. I appreciate the help.
Pouneh