Hi

Try "application.getRealPath(request.getServletPath())" this will give you
the entire path up to and including your JSP page.

I had to do the same thing and this is what I did:

String filePath = application.getRealPath(request.getServletPath());
String jspPath = request.getServletPath();
int filePathLength = filePath.length();
int jspPathLength = jspPath.length();
int copyTo = filePathLength - jspPathLength + 1;
filePath = filePath.substring(0,copyTo);

That means that filePath is everything up to your current directory. Then
you can just stick in you pdf file name and your good to go.

Hope that helped some.

-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of [EMAIL PROTECTED]
Sent: 26 July 2005 06:36 PM
To: [email protected]
Subject: [CTJUG Forum] JSP path issues


Hi,

I am creating a pdf file from a JSP page as follows:

<code>
String reportURL = "Trainee.jasper";
Map parameters = new HashMap();

Connection conn;

conn =
DriverManager.getConnection("jdbc:mysql://server/database","user","pass");

JasperRunManager.runReportToPdfFile(reportURL,"tmp.pdf",parameters,conn);
</code>

It appears to be creating the PDF file in the JBOSS/bin directory on my
local machine (I am deploying via JBoss), which it really shouldn't be
doing, since the rest of my project can't see that directory. Referring
to it using an absolute path is not an option, as this may end up being
deployed by an ISP, where I obviously wouldn't have the chance to
change a whole bunch of pathnames.

I have tried using

request.getRealPath("tmp.pdf")

to get a path that the rest of my project will understand. The path it
returns does not exist; it was only by searching the disk that I
actually managed to find where the file really was.

So:

(1) is there a way of forcing runReportToPdfFile to put the file where
I want it to go? ie to a directory visible to the rest of the project?

(2) how else can I refer to this file? I noticed that
request.getRealPath is deprecated; I couldn't figure out how to do it
properly.

(3) Once I know how to get to the file, if I do this:

<a href="path/filename.pdf">My file</a>

will IE know what to do with the file (assuming Acrobat is installed)?

Reply via email to