Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Jsf relative path?

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Saloon Keeper
Posts: 21239
137
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DON'T DO THAT!!!

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.
 
This cake looks terrible, but it tastes great! Now take a bite out of this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!