You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Francisco J. Bido" <bi...@mac.com> on 2003/03/12 07:45:48 UTC

Reading an XML File From a Servlet

Hi,

I have a controller servlet which reads its configuration information 
from an xml file.  I can do this relative to my local file system.
My question is how to get the servlet to read the xml file from the 
WEB-INF directory once packaged in a typical WAR file.

I'm lost regarding what the steps to follow or where to find a good 
example on how to achieve this.  For example, do I need to
declare a resource in the webapp's web.xml? Any help appreciated.

Thanks!
-FB


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Reading an XML File From a Servlet

Posted by "Francisco J. Bido" <bi...@mac.com>.
Thanks for the tip.  I found a very good article at:

http://www.javaworld.com/javaworld/jw-05-2000/jw-0518-jdom.htm

Best,
-FB


On Wednesday, March 12, 2003, at 12:53  AM, Dan Tran wrote:

> Sorry I dont have an example for you, but all you need is a 
> InputStream to
> your xml file in your war file.  Here is the interface to get it
>
>         InputStream is =
>             servlet.getServletContext().getResourceAsStream(pathName);
>
> Hope it helps
>
> -Dan
>
> ----- Original Message -----
> From: "Francisco J. Bido" <bi...@mac.com>
> To: "Tomcat Users List" <to...@jakarta.apache.org>
> Sent: Tuesday, March 11, 2003 10:45 PM
> Subject: Reading an XML File From a Servlet
>
>
>> Hi,
>>
>> I have a controller servlet which reads its configuration information
>> from an xml file.  I can do this relative to my local file system.
>> My question is how to get the servlet to read the xml file from the
>> WEB-INF directory once packaged in a typical WAR file.
>>
>> I'm lost regarding what the steps to follow or where to find a good
>> example on how to achieve this.  For example, do I need to
>> declare a resource in the webapp's web.xml? Any help appreciated.
>>
>> Thanks!
>> -FB
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Reading an XML File From a Servlet

Posted by Dan Tran <da...@hotmail.com>.
Sorry I dont have an example for you, but all you need is a InputStream to
your xml file in your war file.  Here is the interface to get it

        InputStream is =
            servlet.getServletContext().getResourceAsStream(pathName);

Hope it helps

-Dan

----- Original Message -----
From: "Francisco J. Bido" <bi...@mac.com>
To: "Tomcat Users List" <to...@jakarta.apache.org>
Sent: Tuesday, March 11, 2003 10:45 PM
Subject: Reading an XML File From a Servlet


> Hi,
>
> I have a controller servlet which reads its configuration information
> from an xml file.  I can do this relative to my local file system.
> My question is how to get the servlet to read the xml file from the
> WEB-INF directory once packaged in a typical WAR file.
>
> I'm lost regarding what the steps to follow or where to find a good
> example on how to achieve this.  For example, do I need to
> declare a resource in the webapp's web.xml? Any help appreciated.
>
> Thanks!
> -FB
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org