• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

How to write to a Property file at Run time residing in the WEB-INF

 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,
I am trying to read and write to a property file residing in the WEB-INF folder. I was sucessful in reading the file. I am also partially sucessful writing to this file. The problem i am facing is, not being able to replace the same propery file in WEB-INF folder dynamically. I am wondering if this is possible to do so.
Please have a glance at my method below. The below code is generating a new file SequentialNumber.properties on the root directory of my application Server. I am wondering if there is some way to commit changes to the property file inside my WEB-INF folder.

Thanks all

public void setSequentialNum(String Num)
{
Properties p = new Properties();

p.setProperty("SequentialNum",Num);
try {
//ClassLoader cl = ClassLoader.getSystemClassLoader();

p.store(new FileOutputStream("SequentialNumber.properties"),null);
} catch (IOException ioe) {
System.out.println("error Saving properties file: " + ioe);
}

}
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you are looking for the ServletContext getRealPath method.
getRealPath( "/WEB-INF/SequentialNumber.properties" )
should get you a path usable for FileOutputStream
 
vikram nalagampalli
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried the getServeltContext.getRealPath() but for some reason, /WEB-INF/Seq.properties cannot be found. I am wondering if there is any Permissions to write to WEB-INF.

Thank you
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i dont think /WEB-INF folder requires any special permission to read and write in to the files in that folder. In your previous post u r refering to Seq.properties, is the file name correct??
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I donot think u can write the data back to any file under WEB-INF
folder

Kunal
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no restriction on writing files under WEB-INF. The only restriction observed by the servlet container is that it can't directly serve any files under WEB-INF to a request.
The whole idea of the special WEB-INF directory is that it lets the application developer have a place to read and write files that are protected from outside access AND can be addressed relatively. That lets you distribute a "web application" that will run without having any absolute file paths encoded in it.
Bill
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have tried using Tomcat server. I am able to write to property file.
Only change I made is in the line:

p.store(new FileOutputStream(getServletContext().getRealPath("/WEB-INF/SequentialNumber.properties")),null);
 
What's wrong? Where are you going? Stop! Read this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic