File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes ActionClass.execute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "ActionClass.execute" Watch "ActionClass.execute" New topic


Amy Medrat

Joined: Mar 05, 2006
Posts: 15
Hi All, Need some help.

I want to get the real path of a file and then using this path perform some operation within the action class.
In servlets we used to have servletcontext.getrealpath("file name"),
but within the ActionClass.execute() method how can i get the same information.

[ March 22, 2006: Message edited by: Amy Medrat ]

Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
I have not tried this, but you can get the ServletContext using:

- Brent
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The Action class that your action extends also has a getServlet() method, which returns the ActionServlet instance. Once you have this object, you can get the ServletContext and any other objects you would normally get from your own servlet in a non-Struts application.

Consultant, Sima Solutions
Amy Medrat

Joined: Mar 05, 2006
Posts: 15
Thanks very much Brent and Merrill.
I agree. Here's the link:
subject: ActionClass.execute
Similar Threads
Path used for file creation in a WSAD Web App
Reading external XML file from an Axis Web Service
How to get the complete file path in Mozila
Maven Project loading props file
How to get file path in Struts file upload tag