You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Bob Byron <bb...@radit.com> on 2001/10/03 05:03:37 UTC

Open a file?

Okay, now I need to open the XML file and I am trying to
figure out how to do that.  When I try to open the file "file.xml",
Tomcat 4 is trying to open it relative to "Tomcat\4.0\bin", the
location of the startup scripts.  I want to know what is the 
Tomcat centric way of opening a file relative to the webapp
that it is running under?  I hope I have phrased the question
sufficiently for you to understand what I need to do.  I need
a different reference point, one that uses the webapp itself
as a base.  

Thank You,
Bob Byron


Re: Open a file?

Posted by Bob Byron <bb...@radit.com>.
Does the resource need to be mapped in the web.xml file?

Bob

----- Original Message ----- 
From: "Craig R. McClanahan" <cr...@apache.org>
To: <to...@jakarta.apache.org>
Sent: Wednesday, October 03, 2001 11:28 AM
Subject: Re: Open a file?


> 
> 
> On Tue, 2 Oct 2001, Bob Byron wrote:
> 
> > Date: Tue, 2 Oct 2001 22:03:37 -0500
> > From: Bob Byron <bb...@radit.com>
> > Reply-To: tomcat-user@jakarta.apache.org
> > To: tomcat-user@jakarta.apache.org
> > Subject: Open a file?
> >
> > Okay, now I need to open the XML file and I am trying to
> > figure out how to do that.  When I try to open the file "file.xml",
> > Tomcat 4 is trying to open it relative to "Tomcat\4.0\bin", the
> > location of the startup scripts.  I want to know what is the
> > Tomcat centric way of opening a file relative to the webapp
> > that it is running under?  I hope I have phrased the question
> > sufficiently for you to understand what I need to do.  I need
> > a different reference point, one that uses the webapp itself
> > as a base.
> >
> 
> If you have a file "file.xml" in the top-level directory of your web app,
> open it like this:
> 
>   InputStream stream =
> getServletContext().getResourceAsStream("/file.xml");
> 
> This will work on all servlet containers (not just Tomcat).  It will also
> work when your web app is run directly from a WAR file rather than being
> unpacked.
> 
> > Thank You,
> > Bob Byron
> >
> >
> 
> Craig McClanahan
> 



Re: Open a file?

Posted by Bob Byron <bb...@radit.com>.
Does the resource need to be defined in the web.xml file?
If so, how?

Thank You,
Bob

----- Original Message ----- 
From: "Bob Byron" <bb...@radit.com>
To: <to...@jakarta.apache.org>; <cr...@apache.org>
Sent: Wednesday, October 03, 2001 12:11 PM
Subject: Re: Open a file?


> Thank you Craig!  
> 
> Of course I just sent out a renewed plea for help.  Murphy's
> Law.  I checked for email, sent out my new plea, and 
> then received your email.
> 
> I will be utilizing this technique.  Thanks for the info.
> 
> Bob Byron
> 
> ----- Original Message ----- 
> From: "Craig R. McClanahan" <cr...@apache.org>
> To: <to...@jakarta.apache.org>
> Sent: Wednesday, October 03, 2001 11:28 AM
> Subject: Re: Open a file?
> 
> 
> > 
> > 
> > On Tue, 2 Oct 2001, Bob Byron wrote:
> > 
> > > Date: Tue, 2 Oct 2001 22:03:37 -0500
> > > From: Bob Byron <bb...@radit.com>
> > > Reply-To: tomcat-user@jakarta.apache.org
> > > To: tomcat-user@jakarta.apache.org
> > > Subject: Open a file?
> > >
> > > Okay, now I need to open the XML file and I am trying to
> > > figure out how to do that.  When I try to open the file "file.xml",
> > > Tomcat 4 is trying to open it relative to "Tomcat\4.0\bin", the
> > > location of the startup scripts.  I want to know what is the
> > > Tomcat centric way of opening a file relative to the webapp
> > > that it is running under?  I hope I have phrased the question
> > > sufficiently for you to understand what I need to do.  I need
> > > a different reference point, one that uses the webapp itself
> > > as a base.
> > >
> > 
> > If you have a file "file.xml" in the top-level directory of your web app,
> > open it like this:
> > 
> >   InputStream stream =
> > getServletContext().getResourceAsStream("/file.xml");
> > 
> > This will work on all servlet containers (not just Tomcat).  It will also
> > work when your web app is run directly from a WAR file rather than being
> > unpacked.
> > 
> > > Thank You,
> > > Bob Byron
> > >
> > >
> > 
> > Craig McClanahan
> >


2 webapps 2 jars 1 driver?

Posted by Brian Richards <nc...@pobox.com>.
Ok I am running two applications that use the IBM DB2 appdriver to connect
to two different databases.  The problem is this when i start up tomcat only
one of the applications can access the database.  The first one to have a
request made wins and the other app gets a No Suitable Driver exception.
They both work independtly as long as it's the first one requested.  My
theory is that the Class.forName(driver) being called twice is mucking
things up the code at fault is:

The obeject that owns this code is instatiated in in jspInit() and load is
called only once.

Any other theories?

Thanks

Brian

ps
I'm using Tomcat 3.3, jdk1.3.1 WIN2k. and Apace 1.3.6
and the two applications are in two different virtual hosts

<Context path="/" docBase="E:/csc/513/htdocs" debug="0" reloadable="true"
trusted="false"/>

<Host name="dafs.dyndns.org" >
            <Context path="/messages" docBase="webapps/jive" debug="0"
reloadable="false" trusted="false"/>
</Host>

but i get teh same error when they are both in the same host.



public Connection driverManager()
 throws SQLException
 {
  return  DriverManager.getConnection(getURL(), getUserID(), getPassword());
 }

 public boolean load(Properties prop)
 {
  if (prop!=null) {
   try {
    driver = (String)prop.get("driver");
    password = (String)prop.get("password");
    URL = (String)prop.get("url");
    userID = (String)prop.get("user");
    dataSourceName = (String)prop.get("datasource");
    try {
     Class.forName(getDriver());
    } catch (ClassNotFoundException cnfe) {
     System.err.println(getDriver()+" could not be found.");
    }
   } catch (NullPointerException npe) {
    return false;
   }
  }
  return true;
 }



Re: Open a file?

Posted by Bob Byron <bb...@radit.com>.
Thank you Craig!  

Of course I just sent out a renewed plea for help.  Murphy's
Law.  I checked for email, sent out my new plea, and 
then received your email.

I will be utilizing this technique.  Thanks for the info.

Bob Byron

----- Original Message ----- 
From: "Craig R. McClanahan" <cr...@apache.org>
To: <to...@jakarta.apache.org>
Sent: Wednesday, October 03, 2001 11:28 AM
Subject: Re: Open a file?


> 
> 
> On Tue, 2 Oct 2001, Bob Byron wrote:
> 
> > Date: Tue, 2 Oct 2001 22:03:37 -0500
> > From: Bob Byron <bb...@radit.com>
> > Reply-To: tomcat-user@jakarta.apache.org
> > To: tomcat-user@jakarta.apache.org
> > Subject: Open a file?
> >
> > Okay, now I need to open the XML file and I am trying to
> > figure out how to do that.  When I try to open the file "file.xml",
> > Tomcat 4 is trying to open it relative to "Tomcat\4.0\bin", the
> > location of the startup scripts.  I want to know what is the
> > Tomcat centric way of opening a file relative to the webapp
> > that it is running under?  I hope I have phrased the question
> > sufficiently for you to understand what I need to do.  I need
> > a different reference point, one that uses the webapp itself
> > as a base.
> >
> 
> If you have a file "file.xml" in the top-level directory of your web app,
> open it like this:
> 
>   InputStream stream =
> getServletContext().getResourceAsStream("/file.xml");
> 
> This will work on all servlet containers (not just Tomcat).  It will also
> work when your web app is run directly from a WAR file rather than being
> unpacked.
> 
> > Thank You,
> > Bob Byron
> >
> >
> 
> Craig McClanahan
> 


Re: Open a file?

Posted by Bob Byron <bb...@radit.com>.
Does the resource need to be mapped in the web.xml file?

Bob

----- Original Message ----- 
From: "Craig R. McClanahan" <cr...@apache.org>
To: <to...@jakarta.apache.org>
Sent: Wednesday, October 03, 2001 11:28 AM
Subject: Re: Open a file?


> 
> 
> On Tue, 2 Oct 2001, Bob Byron wrote:
> 
> > Date: Tue, 2 Oct 2001 22:03:37 -0500
> > From: Bob Byron <bb...@radit.com>
> > Reply-To: tomcat-user@jakarta.apache.org
> > To: tomcat-user@jakarta.apache.org
> > Subject: Open a file?
> >
> > Okay, now I need to open the XML file and I am trying to
> > figure out how to do that.  When I try to open the file "file.xml",
> > Tomcat 4 is trying to open it relative to "Tomcat\4.0\bin", the
> > location of the startup scripts.  I want to know what is the
> > Tomcat centric way of opening a file relative to the webapp
> > that it is running under?  I hope I have phrased the question
> > sufficiently for you to understand what I need to do.  I need
> > a different reference point, one that uses the webapp itself
> > as a base.
> >
> 
> If you have a file "file.xml" in the top-level directory of your web app,
> open it like this:
> 
>   InputStream stream =
> getServletContext().getResourceAsStream("/file.xml");
> 
> This will work on all servlet containers (not just Tomcat).  It will also
> work when your web app is run directly from a WAR file rather than being
> unpacked.
> 
> > Thank You,
> > Bob Byron
> >
> >
> 
> Craig McClanahan
> 



Re: Open a file?

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Tue, 2 Oct 2001, Bob Byron wrote:

> Date: Tue, 2 Oct 2001 22:03:37 -0500
> From: Bob Byron <bb...@radit.com>
> Reply-To: tomcat-user@jakarta.apache.org
> To: tomcat-user@jakarta.apache.org
> Subject: Open a file?
>
> Okay, now I need to open the XML file and I am trying to
> figure out how to do that.  When I try to open the file "file.xml",
> Tomcat 4 is trying to open it relative to "Tomcat\4.0\bin", the
> location of the startup scripts.  I want to know what is the
> Tomcat centric way of opening a file relative to the webapp
> that it is running under?  I hope I have phrased the question
> sufficiently for you to understand what I need to do.  I need
> a different reference point, one that uses the webapp itself
> as a base.
>

If you have a file "file.xml" in the top-level directory of your web app,
open it like this:

  InputStream stream =
	getServletContext().getResourceAsStream("/file.xml");

This will work on all servlet containers (not just Tomcat).  It will also
work when your web app is run directly from a WAR file rather than being
unpacked.

> Thank You,
> Bob Byron
>
>

Craig McClanahan