IMHO the simplest way for you is to get the root of your application in a ServletContextListener
declared in web.xml or via a WebListener
annotation and to store it in a static variable.
public class RootPathHolder implements ServletContextListener {
static String rootPath;
public void contextInitialized(ServletContextEvent sce) {
RootServletListener.rootPath = sce.getServletContext().getRealPath("/");
}
public void contextDestroyed(ServletContextEvent sce) {
}
public static String getRootPath() {
return rootPath;
}
}
That way you will have access to the root path of your application from anywhere as RootPathHolder.getRootPath()
and in your interceptor you will only need to do a path concatenation :
Path realPath = Paths.get(RootPathHolder.getRootPath(), "photo/test.txt");