aspose file tools*
The moose likes Struts and the fly likes How to get servlet context or similar object in Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to get servlet context or similar object in Struts" Watch "How to get servlet context or similar object in Struts" New topic
Author

How to get servlet context or similar object in Struts

Dhiren Joshi
Ranch Hand

Joined: Dec 09, 2003
Posts: 463
I need handle to ServletContext becuase I need the access to this method .
getRealPath() in servlet context. Can any one tell me how I could get this using Struts in my Action classes.

Thanks
Dhiren
Samuel Cox
Ranch Hand

Joined: Nov 16, 2004
Posts: 96

For struts 1.1 (not sure on latest):


[ June 17, 2005: Message edited by: Samuel Cox ]
Dhiren Joshi
Ranch Hand

Joined: Dec 09, 2003
Posts: 463
I can make this call even in Struts action classes ?

this.getServlet().getServletContext().getRealPath("blah");

Thanks
Dhiren
Samuel Cox
Ranch Hand

Joined: Nov 16, 2004
Posts: 96

Well, I have never used the getRealPath(String) method, but I have used other methods of ServletContext from our Action classes (execute method) using that construct.

Remember, that was for struts 1.1. You'll need to make sure you can do this for whatever version you are using.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get servlet context or similar object in Struts