wood burning stoves 2.0*
The moose likes JSF and the fly likes Getting the path for data files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Getting the path for data files" Watch "Getting the path for data files" New topic
Author

Getting the path for data files

Christopher Sharp
Ranch Hand

Joined: Dec 12, 2007
Posts: 152
Thanks for the reply on the JAR files in a previous thread. That problem has been fixed for now.

I have another question. How do you write to or read from data files in a JSF project an Eclipse? I want to have a folder called, say data, immediately below the project folder, into which I can read and write files. If I use dir.getCanonicalPath() or System.getProperty("user.dir") to find the location of the default folder, I found that it is in the config folder of the Glassfish server I am using with Eclipse and JSF. This is not what I want.

In using Google I found examples using code like:

ServletContext servletContext = (ServletContext) externalContext.getContext();
String webContentRoot = servletContext.getRealPath("/");

but I can never get something like that to work, because either an abstract class is used or an interface.

An example of my code is here:



In this particular case it is complaining that getCcontext() is undefined. Various attemps to sort this out have so far failed, and I have spent quite a lot of time on this, so some help would be most appreciated. I am sure there is something that has to be done correctly concerning how ServletContext must be declared correctly.

This is a JSF 1.2 application that I want to modify, before moving to JSF 2.0.

Your help for this would be most apprectiated.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15950
    
  19

Don't store data files inside your webapp. It's a violation of the J2EE standard, won't work on all webapp servers, and when it does, sooner or later, it will bite you. Use an independent directory for data that's located somewhere outside both the webapp (WAR) and the webapp server.


Customer surveys are for companies who didn't pay proper attention to begin with.
Christopher Sharp
Ranch Hand

Joined: Dec 12, 2007
Posts: 152
OK, many thanks for your helpful advice. I am now instead going to use a folder in my desktop using System.getProperty("user.home") to get the path, then appending \Desktop and \Folder-Name to store the data files as a temporray measure for development and testing. Eventually this will be changed when the code will be moved onto an online server.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting the path for data files
 
Similar Threads
Unit testing class that deals with file I/O
Using imageCropper with JSF and primefaces
how to obtain the response object in jsf
How create csv format from existing pdf format in Jsf?
Sharing bean with Servlet & JSP