java - Accessing Files From Web Document Root -


i'm using spring mvc 3.0 , tomcat.

i have bean has property value should path rooted web document root. example, specify value in spring configuration file following.

<bean id="mybean" class="com.stackoverflow.bean">     <property name="path" value="/web-inf/foo.xml" /> </bean> 

where take value can read file? spring/spring mvc provide transparent way access resources within document root?

in order real path resource need have access servletcontext

one way achieve make com.stackoverflow.bean implement servletcontextaware interface. upon restart, server should hand on instance of servletcontext bean (you have include following code)

private servletcontext ctx; public void setservletcontext(servletcontext servletcontext) {     ctx = servletcontext; } 

finally, use ctx.getrealpath(path) real path resource.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -