Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting the path for data files

 
Christopher Sharp
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18157
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Christopher Sharp
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic