struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jason Long" <ja...@supernovasoftware.com>
Subject RE: application.getRealPath("/") from ActionForm???
Date Sun, 30 Mar 2003 03:49:24 GMT
Actually I am calling a funtion that loads values into the form in the
object.  This load method needs to find a relative path.  I cannot seem to
get a reference to the controller servlet or any other way to get the path
to my WEB-INF.

public final class ManagerForm extends ActionForm {
  public ManagerForm() throws Exception {
    this.load();
  }
...
....
...
}

-----Original Message-----
From: Dan Tran [mailto:danttran@hotmail.com]
Sent: Saturday, March 29, 2003 8:25 PM
To: Struts Users Mailing List
Subject: Re: application.getRealPath("/") from ActionForm???


If you deploy your app as a WAR file, then it is the correct result since
there is no real directory to return

But you can use this code

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

where pathName is the context path to your file in the WAR archive. (ie
/WEB-INF/yourFileName.txt)

Good luck.

-Dan
----- Original Message -----
From: "Jason Long" <jason@supernovasoftware.com>
To: "Struts Users Mailing List" <struts-user@jakarta.apache.org>
Sent: Saturday, March 29, 2003 1:07 PM
Subject: application.getRealPath("/") from ActionForm???


> When deploying my Struts application I ran in to a small problem.
> I had hard coded the path to an xml file used to load values into my form.
> I need to get a relative path.  I tried the following, but got a null
> pointer.
>
> ActionServlet as = this.getServlet();
> ServletContext application = as.getServletConfig().getServletContext();
> String basePath = application.getRealPath("/");
>
> Thanks for your time,
> Jason Long - CEO and Chief Software Engineer
> Supernova Software - supernovasoftware.com
> BS Physics, MS  Chemical Engineering
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>

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



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


Mime
View raw message