Hi,

your PDF file has to be accessible for tomcat, for example:
Imagine your web application is stored under
%TOMCAT_ROOT%/webapps/yourapp
Then your PDF file has to be somewhere in your 'yourapp'
directory. It is the same as html pages: you referene them
(e.g. in html) with <a href="foo.html"> - relative path.
So this link in http://localhost/bla.html will link to
http://localhost/foo.html.

Try this: put your PDF file under your webapp-root (called
'yourapp' above...) directory. And in your jsp:

response.setRedirect(outPDF);
// outPDF is  "TMP.PDF" (without c:....)
// tomcat will look for 'yourapp/TMP.PDF'
// If your JSP is e.g. accessible under http://localhost/myjsp.jsp
// it will redirect to http://localhost/TMP.PDF which is also
// remote accessible (if read access is permitted)

I never tried response.setRedirect(), but I think this will work ;-)

Marko


At 17:05 06.11.2002 +0100, you wrote:

I tried it , it works, but I have one great suspicion:

Will it work even on remote server ?

response.sendRedirect(outPDF);           // outPDF is "C:/Program
Files/Apache Tomcat 4.0/Fop/TMP.PDF"

I have Tomcat and browser on one PC . Doesn't the browser thus open the PDF
file directly, bypassing Tomcat ?
If so, I think I should use URL as parameter. But how can I find out http
address from inside the servlet?

Thanks for any comments.


> [EMAIL PROTECTED] wrote: > > > Yesterday, after a few good advices there from fop users I successfuly used > > this code to show pdf content in browser. It works in my JDeveloper 9i. > > > > File inputFile = new File(pdfFile); > > FileReader fr = new FileReader(inputFile); > > > > ByteArrayOutputStream baos = new ByteArrayOutputStream(); > > int ch; > > while((ch = fr.read()) != -1) { > > baos.write(ch); > > } > > > > byte[] content = baos.toByteArray(); > > response.setContentType("application/pdf"); > > response.setContentLength(content.length); > > response.getOutputStream().write(content); > > response.getOutputStream().flush(); > > Looks too convolute to me. If you have already created pdf file on a disk, why > do you process it by hands instead of rely on a web server? Just redirect > browser to the file, that will emulate reading static pdf, which works okay > even in IE (well, at least if extension is pdf). > I mean > response.sendRedirect("/foo/bar.pdf"); > > -- > Oleg Tkachenko > eXperanto team > Multiconn Technologies, Israel



Reply via email to