You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Jacob Rhoden <ja...@uptecs.com> on 2007/07/14 10:14:28 UTC
Read and write inside WEB-INF
Hi,
I have seen a few apps do this now and I would like to do it, to have a
configure page that read and writes a properties file somewhere inside
the WEB-INF directory. That said, I have been researching and cant find
out where, what is the correct way to find the location of your WEB-INF
directory (or your apps directory for that matter).
Best Regards,
Jacob
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Read and write inside WEB-INF
Posted by Manivannan Palanichamy <ma...@gmail.com>.
I too do the same thing; I am reading properties from a property file, thats
under WEB-INF/classes directory.
code is: InputStream in = getClass().getClassLoader().getResourceAsStream("
sample.properties");
Code is working fine.
--
Manivannan.Palanichamy (@) Oracle.com
http://mani.gw.googlepages.com/index.html
On 7/14/07, Jacob Rhoden <ja...@uptecs.com> wrote:
>
> Hi,
>
> I have seen a few apps do this now and I would like to do it, to have a
> configure page that read and writes a properties file somewhere inside
> the WEB-INF directory. That said, I have been researching and cant find
> out where, what is the correct way to find the location of your WEB-INF
> directory (or your apps directory for that matter).
>
> Best Regards,
> Jacob
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
--
Manivannan.Palanichamy (@) Oracle.com
http://mani.gw.googlepages.com/index.html
Re: Read and write inside WEB-INF
Posted by hanasaki <ha...@hanaden.com>.
Confirmed. A real pain in the bum... I do not let my folks use unpacked
WARs. There were once a bunch of guys that put custom log files in the
unpacked WAR directory... shame shame.
David Smith wrote:
> Only works for unpacked web applications. If you attempt getRealPath
> from inside a packed war file it will return null.
>
> --David
>
>
> hanasaki wrote:
>> Hmmm does this work for packed WAR's or only Unpacked... ?
>>
>> Jacob Rhoden wrote:
>>
>>> Much Appreciated! Thanks.
>>>
>>> Edoardo Panfili wrote:
>>>
>>>> Jacob Rhoden ha scritto:
>>>>
>>>>> what is the correct way to find the location of your WEB-INF
>>>>> directory (or your apps directory for that matter).
>>>>>
>>>>>
>>>> try with
>>>> String x = this.getServletContext().getRealPath("WEB-INF");
>>>>
>>> ---------------------------------------------------------------------
>>> To start a new topic, e-mail: users@tomcat.apache.org
>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Read and write inside WEB-INF
Posted by David Smith <dn...@cornell.edu>.
Only works for unpacked web applications. If you attempt getRealPath
from inside a packed war file it will return null.
--David
hanasaki wrote:
> Hmmm does this work for packed WAR's or only Unpacked... ?
>
> Jacob Rhoden wrote:
>
>> Much Appreciated! Thanks.
>>
>> Edoardo Panfili wrote:
>>
>>> Jacob Rhoden ha scritto:
>>>
>>>> what is the correct way to find the location of your WEB-INF
>>>> directory (or your apps directory for that matter).
>>>>
>>>>
>>> try with
>>> String x = this.getServletContext().getRealPath("WEB-INF");
>>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Read and write inside WEB-INF
Posted by Joe Nathan <jo...@yahoo.com>.
This is quite tricky issue. I use the following method.
Basically it locate the directory where you place your
designated class definition!
============================================
static String base;
static {
try {
// use an object instance which is part of service!
my.package.MyObject rm = new my.package.MyObject();
Class c = rm.getClass();
String name = "my.package.MyObject.class";
URL url = c.getClassLoader().getResource(name);
String st1 = url.getPath();
int x = st1.indexOf("file:"); // remvie "jar:file:" part;
if (x>=0) st1 = st1.substring(x+5);
x = st1.indexOf(":"); // remove leading "/" for Windows!
if (x>=0) st1 = st1.substring(1);
st1 = st1.substring(0, st1.length()-name.length()-1); // remove /class
name;
if (st1.endsWith("!")) { // remove jar/war/aar/mar file paths;
x = st1.lastIndexOf("/");
if (x>=0) st1 = st1.substring(0, x);
}
st1 = st1.replace("/", File.separator); // directory;
base = st1+File.separator;
System.out.println("Base: "+base);
} catch (Throwable t1) {
t1.printStackTrace();
}
}
--
View this message in context: http://www.nabble.com/Read-and-write-inside-WEB-INF-tf4078368.html#a11597896
Sent from the Tomcat - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Read and write inside WEB-INF
Posted by hanasaki <ha...@hanaden.com>.
Hmmm does this work for packed WAR's or only Unpacked... ?
Jacob Rhoden wrote:
> Much Appreciated! Thanks.
>
> Edoardo Panfili wrote:
>> Jacob Rhoden ha scritto:
>>> what is the correct way to find the location of your WEB-INF
>>> directory (or your apps directory for that matter).
>>>
>> try with
>> String x = this.getServletContext().getRealPath("WEB-INF");
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Read and write inside WEB-INF
Posted by Jacob Rhoden <ja...@uptecs.com>.
Much Appreciated! Thanks.
Edoardo Panfili wrote:
> Jacob Rhoden ha scritto:
>> what is the correct way to find the location of your WEB-INF
>> directory (or your apps directory for that matter).
>>
> try with
> String x = this.getServletContext().getRealPath("WEB-INF");
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Read and write inside WEB-INF
Posted by Edoardo Panfili <ed...@aspix.it>.
Jacob Rhoden ha scritto:
> Hi,
>
> I have seen a few apps do this now and I would like to do it, to have a
> configure page that read and writes a properties file somewhere inside
> the WEB-INF directory. That said, I have been researching and cant find
> out where, what is the correct way to find the location of your WEB-INF
> directory (or your apps directory for that matter).
>
> Best Regards,
> Jacob
>
try with
String x = this.getServletContext().getRealPath("WEB-INF");
Edoardo
--
Jabber: edoardopa@talk.google.com
tel: 075 9142766
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org