Set path in web.xml relative to WEB-INF
I want to set a path in my web.xml which is relative to the WEB-INF or the WEB-INF/classes.
However, the following code (repository.home) seems to pick up a path relative to c: root drive path on my windows machine here.
<servlet>
<servlet-name>ContentRepository</servlet-name>
<servlet-class>org.apache.jackrabbit.servlet.jackrabbit.JackrabbitRepositoryServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>repository.home</param-name>
<param-value>/WEB-INF/classes/testit</param-value>
</init-param>
</servlet>
<servlet>
<servlet-name>JackrabbitServlet</servlet-name>
<servlet-class>com.orsa.seam.JackrabbitServlet</servlet-class>
<load-on-startup>2</load-on-startup>
&l开发者_C百科t;/servlet>
That parameter is OK, i.e. when you read it, it will be still a String with the value:
/WEB-INF/classes/testitA parameter in web.xml file is just a parameter - it's not a "path".
So the question is what you do with that parameter?
Since you are trying to access resources(files) inside a servlet container, you need to use specific methods, e.g. something like
ServletContext#getRealPath()
to get the real path of e.g. /WEB-INF/classes/testit, than
append to it what you need (thus having a full path to those files inside that directory), or subtract it from other "full paths", thus having the relative paths to it. E.g. if you have '/testit/test1.txt' '/testit/test2.txt' you can access those files by just appending them to the real path obtained above.
Or subtract that path from other 'full paths', thus having the relative path to your parameter. E.g. if you have the full path (c:/tomcat/webapps/myapp/WEB-INF/data/testit/test.txt), than you just need to subtract that full path of your parameter, so you will obtain the relative path: '/testit/test2.txt'
精彩评论