
Signature
Real Gagnon from Quebec, Canada
* Looking for Java or PB code examples ? Visit Real's How-to
* http://www.rgagnon.com/howto.html
> Try application.getRealPath("WEB_INF"); in your JSP.
Oups ... application.getRealPath("/WEB-INF");
Bye.

Signature
Real Gagnon from Quebec, Canada
* Looking for Java or PB code examples ? Visit Real's How-to
* http://www.rgagnon.com/howto.html
>> I have a Java webapp (using Tomcat) with a JSP and a class extending
>> Action. The user selects an option in the jsp. The input is forwarded
>> to the class using Struts. It is now the task of the class to store
>> the setting in the WEB-INF/ directory.
>
> Try application.getRealPath("WEB_INF"); in your JSP.
Yes, this may work in the JSP and from the JSP I can forward this property to a
ActionForm or to the session. But I thought there must be a way to directly
get the directory in the Action class or even in a bean class.
Sebastian
Luke Webber - 08 Dec 2005 23:06 GMT
>>>I have a Java webapp (using Tomcat) with a JSP and a class extending
>>>Action. The user selects an option in the jsp. The input is forwarded
[quoted text clipped - 6 lines]
> ActionForm or to the session. But I thought there must be a way to directly
> get the directory in the Action class or even in a bean class.
Not directly, but you could try one of several things. You could keep a
static or singleton class that keeps your configuration info, and store
the directory path there when it's first initialised from your servlet
or JSP. Or you could use System.setProperty("user.dir", <path>) to
achive the same result, then just call System.getProperty("user.dir") to
retrieve it.
HTH,
Luke
John C. Bollinger - 09 Dec 2005 00:46 GMT
>>>I have a Java webapp (using Tomcat) with a JSP and a class extending
>>>Action. The user selects an option in the jsp. The input is forwarded
[quoted text clipped - 6 lines]
> ActionForm or to the session. But I thought there must be a way to directly
> get the directory in the Action class or even in a bean class.
In JSP the automatic variable "application" is a reference to the JSP's
ServletContext. I'm not much familiar with the details of Struts, but
if you can get a hold of the ServletContext through some Struts
mechanism then you can do the same thing with it that you can do in JSP
scriptlet code.

Signature
John Bollinger
jobollin@indiana.edu
Hiran Chaudhuri - 09 Dec 2005 18:57 GMT
>> Try application.getRealPath("WEB_INF"); in your JSP.
>
[quoted text clipped - 3 lines]
> directly
> get the directory in the Action class or even in a bean class.
The struts action class has the request, right?
Then do an request.getSession().getServletContext().getRealPath(...)
For business logic you do not want to be dependent on the servlet api. So in
any case your action should get the path and pass it on to your business
logic.
Hiran