File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes Jsf relative path? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Jsf relative path?" Watch "Jsf relative path?" New topic

Jsf relative path?

Mark Dragan

Joined: Sep 28, 2010
Posts: 18
Hi everybody,
I have question regarding the relative path, in my application I'm using itext jar and user can create Pdf and question is how can I store it to the folder Pdf that is under the
Web Pages folder. I try using new FileOutputStream("/Pdf/hello.pdf") but nothing happens.
Thanks in advance.
Mark Dragan

Joined: Sep 28, 2010
Posts: 18
I found solution if anyone needs it:

ExternalContext context=FacesContext.getCurrentInstance().getExternalContext();
String s=context.getRealPath("MenusPdf/");
PdfWriter.getInstance(document, new FileOutputStream(s+"/hello.pdf"));

First I get external context and then I get real path to folder where I want to save my pdf file and then write it.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641


You should never attempt to write any sort of files into your WAR. Treat it as a read-only resource. On a lot of servers, depending on configuration, it is a read-only resource.

On the rest of them, you can get into a lot of trouble writing stuff into a WAR. For one thing, a redeployment will destroy your data.

Always select an external directory and put your data there. What directory you select is up to you, but it shouldn't be part of a WAR or part of the server.

Customer surveys are for companies who didn't pay proper attention to begin with.
subject: Jsf relative path?
Similar Threads
Printing through Javascript? Urgent!!!
Path for images in xsl:fo
changing filename after uploading image
Read Text File Using Relative Path.
path used in getRequestDispatcher()?