ディレクトリ blog の下で webapp を実行しています。(例: www.example.com/blog)。
リクエストの実際のファイルシステム パスを取得したいと考えています。
例: www.example.com/blog/test-file.html -> /usr/share/tomcat7/webapps/blog/test-file.html
私は次のことを試しました:
public String realPath(HttpServletRequest request, ServletContext servletContext){
String requestURI = request.getRequestURI();
String realPath = servletContext.getRealPath(requestURI);
return realPath;
}
ただし、これは戻ります
/usr/share/tomcat7/webapps/blog/blog/test-file.html
これを行う正しい方法は何ですか?