You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Angelo Chen <an...@yahoo.com.hk> on 2007/09/01 16:10:45 UTC

T5: xml file location

Hi,
I have this info.xml file that I need to open, first I put it under WEB-INF
and use : fr = new FileReader("info.xml"); got FileNotFoundException, I put
it under images directory as the template was able to get the pictures
there, then I use FileReader("images/info.xml"), same exception. where is
the better place to put xml files and what's the correct path to access
them? thanks.

A.C.
-- 
View this message in context: http://www.nabble.com/T5%3A-xml-file-location-tf4364651.html#a12440650
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: xml file location

Posted by Josh Canfield <jo...@thedailytube.com>.
> I tried your second approach:
> requestGlobals.getHTTPServletRequest
> ().getSession().getServletContext().getRealPath("app")
>
> it returns : /usr/local/apache-tomcat-5.5.23/webapps/my_app_context/app
>
> but I checked the running program, the file is here
> /usr/local/apache-tomcat-5.5.23/webapps/ROOT/WEB-INF/info.xml
>

I don't have the time to figure this out right now. I would guess that it's
either a bug in the way tomcat is figuring out the context or in how you are
deploying. You could try passing "ROOT" instead of "app" but I don't know
that it will work. You should search tomcat forums for how this works.

Josh


On 9/1/07, Angelo Chen <an...@yahoo.com.hk> wrote:
>
>
> Hi Josh,
>
> I tried your second approach:
> requestGlobals.getHTTPServletRequest
> ().getSession().getServletContext().getRealPath("app")
>
> it returns : /usr/local/apache-tomcat-5.5.23/webapps/my_app_context/app
>
> but I checked the running program, the file is here
> /usr/local/apache-tomcat-5.5.23/webapps/ROOT/WEB-INF/info.xml
>
> if I set the application context to "/", i got
>
> /usr/local/apache-tomcat-5.5.23/webapps/app  and the file still in the
> same
> place, seems difficult to link the real path to the actual WEB-INF, any
> idea? Thanks,
>
> A.C.
>
>
>
>
>
> Josh Canfield-2 wrote:
> >
> > Since, I assume, you are deploying your web application into a servlet
> > container you are not going to be able to use a relative path to get at
> > the
> > file. Tapestry isn't doing the loading of the file so using any Tapestry
> > related path constructs is not going to work.
> >
> > Your best bet is putting your file in the classpath and using the
> > classloader's getResource or getResourceAsStream methods to load it.
> >
> > You could also try to use the ServletContext to find where it's
> physically
> > loaded on the disk
> > String path = request.getSession
> ().getServletContext().getRealPath("app");
> > // app is the name of your servlet/filter
> > But there are some significant caveats:
> > If you are using a secure app server then you may or may not be allowed
> to
> > read the file from this location.
> > If you have deployed into a WAR file then this also may not help (if the
> > WAR
> > isn't exploded).
> >
> > So, put it in the classpath and use the classloader to find it.
> >
> > Josh
> >
> > On 9/1/07, Angelo Chen <an...@yahoo.com.hk> wrote:
> >>
> >>
> >> Hi,
> >> I have this info.xml file that I need to open, first I put it under
> >> WEB-INF
> >> and use : fr = new FileReader("info.xml"); got FileNotFoundException, I
> >> put
> >> it under images directory as the template was able to get the pictures
> >> there, then I use FileReader("images/info.xml"), same exception. where
> is
> >> the better place to put xml files and what's the correct path to access
> >> them? thanks.
> >>
> >> A.C.
> >> --
> >> View this message in context:
> >> http://www.nabble.com/T5%3A-xml-file-location-tf4364651.html#a12440650
> >> Sent from the Tapestry - User mailing list archive at Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> >> For additional commands, e-mail: users-help@tapestry.apache.org
> >>
> >>
> >
> >
> > --
> > --
> > TheDailyTube.com. Sign up and get the best new videos on the internet
> > delivered fresh to your inbox.
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/T5%3A-xml-file-location-tf4364651.html#a12445945
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
--
TheDailyTube.com. Sign up and get the best new videos on the internet
delivered fresh to your inbox.

Re: T5: xml file location

Posted by Angelo Chen <an...@yahoo.com.hk>.
Hi Josh,

I tried your second approach:
requestGlobals.getHTTPServletRequest().getSession().getServletContext().getRealPath("app")

it returns : /usr/local/apache-tomcat-5.5.23/webapps/my_app_context/app

but I checked the running program, the file is here
/usr/local/apache-tomcat-5.5.23/webapps/ROOT/WEB-INF/info.xml

if I set the application context to "/", i got 

/usr/local/apache-tomcat-5.5.23/webapps/app  and the file still in the same
place, seems difficult to link the real path to the actual WEB-INF, any
idea? Thanks,

A.C.





Josh Canfield-2 wrote:
> 
> Since, I assume, you are deploying your web application into a servlet
> container you are not going to be able to use a relative path to get at
> the
> file. Tapestry isn't doing the loading of the file so using any Tapestry
> related path constructs is not going to work.
> 
> Your best bet is putting your file in the classpath and using the
> classloader's getResource or getResourceAsStream methods to load it.
> 
> You could also try to use the ServletContext to find where it's physically
> loaded on the disk
> String path = request.getSession().getServletContext().getRealPath("app");
> // app is the name of your servlet/filter
> But there are some significant caveats:
> If you are using a secure app server then you may or may not be allowed to
> read the file from this location.
> If you have deployed into a WAR file then this also may not help (if the
> WAR
> isn't exploded).
> 
> So, put it in the classpath and use the classloader to find it.
> 
> Josh
> 
> On 9/1/07, Angelo Chen <an...@yahoo.com.hk> wrote:
>>
>>
>> Hi,
>> I have this info.xml file that I need to open, first I put it under
>> WEB-INF
>> and use : fr = new FileReader("info.xml"); got FileNotFoundException, I
>> put
>> it under images directory as the template was able to get the pictures
>> there, then I use FileReader("images/info.xml"), same exception. where is
>> the better place to put xml files and what's the correct path to access
>> them? thanks.
>>
>> A.C.
>> --
>> View this message in context:
>> http://www.nabble.com/T5%3A-xml-file-location-tf4364651.html#a12440650
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
> 
> 
> -- 
> --
> TheDailyTube.com. Sign up and get the best new videos on the internet
> delivered fresh to your inbox.
> 
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-xml-file-location-tf4364651.html#a12445945
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: xml file location

Posted by Angelo Chen <an...@yahoo.com.hk>.
Hi Marcus,

I checked, it seams using java.io.tempdir.


Marcus-11 wrote:
> 
> Angelo,
> 
> Look at Tapestry-Upload source code.
> There should be an example.
> 
> Marcus
> 
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-xml-file-location-tf4364651.html#a12445874
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: xml file location

Posted by Marcus <mv...@gmail.com>.
Angelo,

Look at Tapestry-Upload source code.
There should be an example.

Marcus

Re: T5: xml file location

Posted by Josh Canfield <jo...@thedailytube.com>.
Since, I assume, you are deploying your web application into a servlet
container you are not going to be able to use a relative path to get at the
file. Tapestry isn't doing the loading of the file so using any Tapestry
related path constructs is not going to work.

Your best bet is putting your file in the classpath and using the
classloader's getResource or getResourceAsStream methods to load it.

You could also try to use the ServletContext to find where it's physically
loaded on the disk
String path = request.getSession().getServletContext().getRealPath("app");
// app is the name of your servlet/filter
But there are some significant caveats:
If you are using a secure app server then you may or may not be allowed to
read the file from this location.
If you have deployed into a WAR file then this also may not help (if the WAR
isn't exploded).

So, put it in the classpath and use the classloader to find it.

Josh

On 9/1/07, Angelo Chen <an...@yahoo.com.hk> wrote:
>
>
> Hi,
> I have this info.xml file that I need to open, first I put it under
> WEB-INF
> and use : fr = new FileReader("info.xml"); got FileNotFoundException, I
> put
> it under images directory as the template was able to get the pictures
> there, then I use FileReader("images/info.xml"), same exception. where is
> the better place to put xml files and what's the correct path to access
> them? thanks.
>
> A.C.
> --
> View this message in context:
> http://www.nabble.com/T5%3A-xml-file-location-tf4364651.html#a12440650
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
--
TheDailyTube.com. Sign up and get the best new videos on the internet
delivered fresh to your inbox.

Re: T5: xml file location

Posted by Angelo Chen <an...@yahoo.com.hk>.
Hi Marcus,

This does not work neither, kind of strange.


Marcus-11 wrote:
> 
> Hi Angelo,
> 
> try FileReader("context:images/info.xml")
> 
> Marcus
> 
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-xml-file-location-tf4364651.html#a12441264
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: xml file location

Posted by Marcus <mv...@gmail.com>.
with "images" under "youApp\src\main\webapp\"

Re: T5: xml file location

Posted by Marcus <mv...@gmail.com>.
Hi Angelo,

try FileReader("context:images/info.xml")

Marcus