--- On Wed, 8/13/08, Struts Two wrote: > Assuming you have a file named "test.txt" at the > root of your webapp, you can get the absolute path name to > the file with the following code snippet in ur interceptor. > ActionContext context = actionInvocation.getInvocationContext(); > HttpServletRequest request = (HttpServletRequest) > context.get("com.opensymphony.xwork2.dispatcher.HttpServletRequest"); > String completeFilename = > request.getSession().getServletContext().getRealPath("test.txt");
I think Paul's point was that if you're deploying a WAR/EAR that won't work, hence when possible it's best to avoid such things. It's also cleaner to get the request via ActionContext. Cleaner still by implementing ServletRequestAware as then being tied to the servlet spec is stated explicitly. (I'm also always nervous about using a string literal to identify an attribute when there's a defined String for it already.) If the goal is to load a file then putting it on the classpath and loading it as a resource is cleaner and safer. If it's for writing then I'd be nervous about that too; seems like it'd be a better idea to write to somewhere outside of the webapp :/ Dave > ----- Original Message ---- > From: Paul Benedict <[EMAIL PROTECTED]> > To: Struts Users Mailing List > <user@struts.apache.org> > Sent: Tuesday, August 12, 2008 6:56:24 PM > Subject: Re: Get path to the webapp > > Vasyl, > > The attempt is very iffy. Some things you need to know: > > 1) No Servlet API provides the path to your files. > > 2) If running in a WAR file that is never expanded, there > will be no > such file directory that will exist. > > 3) You can use the classloader of the web context to get > the root of > your web application, but that assumes #2 is false. You > must be on a > file system for it to work. > > Paul > > On Tue, Aug 12, 2008 at 8:04 AM, Vasyl Skrypij > <[EMAIL PROTECTED]> wrote: > > > > Hi all > > > > I have Struts 2.0.9 > > > > I need to get the path to the directory in which my > web application is > > situated during interceptor's asking. How can I do > this been using > > ActionInvocation class object which passes into > intercept method, or maybe i > > should try some other way? > > > > -- > > View this message in context: > http://www.nabble.com/Get-path-to-the-webapp-tp18943905p18943905.html > > Sent from the Struts - User mailing list archive at > Nabble.com. > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: > [EMAIL PROTECTED] > > For additional commands, e-mail: > [EMAIL PROTECTED] > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: > [EMAIL PROTECTED] > > > > __________________________________________________________________ > Yahoo! Canada Toolbar: Search from anywhere on the web, and > bookmark your favourite sites. Download it now at > http://ca.toolbar.yahoo.com. > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: > [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]