On Wed, 30 Jul 2003, Simon Kelly wrote:
> Date: Wed, 30 Jul 2003 15:47:55 +0200 > From: Simon Kelly <[EMAIL PROTECTED]> > Reply-To: Struts Users Mailing List <[EMAIL PROTECTED]> > To: Struts Users Mailing List <[EMAIL PROTECTED]> > Subject: Re: [OT] Best super-class for context handling. > > Ah, right. > > Not sure whether that's what I'm after. > > Here's a better explination. > > I am using files that are contained within the /WEB-INF/ dir within the web > application to hold information required by the business logic. These files > are not part of the controller or view but are required to generate the > content data for the action classes. So I need something that will get the > paths regardless of the enviroment they are in. I have chosen to pass all > file names within the business logic in the form /WEB-INF/dir/file.x and > have been using context.getRealPath() [or the correct method if that's > wrong] to get the path name (which I had thought would be ok as it will > always return the correct path regardless of where the webapp is deployed). > > Is this wrong, and is there a better way to do it? > Assuming you're in an Action, do this: InputStream is = servlet.getServletContext().getResourceAsStream("/WEB-INF/dir/file.x"); It will be portable everywhere, even if you end up running on containers that don't expand your webapp into an unpacked directory -- in those environments, getRealPath() will return null. > Cheers > > Simon > Craig --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]