mjgirl
mjgirl

Reputation: 41

Path to WebContentFile in Spring

I'm using Spring 3 and would like to get the path to a folder I have created under the WebContent folder. I want to create a File instance there.

Upvotes: 0

Views: 204

Answers (1)

axtavt
axtavt

Reputation: 242686

A real path to the file under webapp root can be obtained using ServletContext.getRealPath().

Note that this method may return null if the concept of real path has no sense in your deployment configuration (for example, application is deployed as an unpacked .war), in this case you can't create a file there.

An instance of ServletContext in Spring can be autowired.

Upvotes: 1

Related Questions