How to get file system path of the context root of any application

后端 未结 1 1938
生来不讨喜
生来不讨喜 2021-01-21 07:58

I am working on web application.I invoke on my jsp request.getContextPath(), but strangely I got address /streetshop.

Then I am appending some

相关标签:
1条回答
  • 2021-01-21 08:21

    You mix things up here. HttpServletRequest.getContextPath() returns your web application root path. In your example this is /streetshop, so your URL may look similar to www.myapp.com/streetshop. If you want to access the internal file system path, you must obtain it from the ServletContext using request.getServletContext().getRealPath("/"). This should return the location of your WAR files' WebContent folder.

    Keep in mind that if you modify contents of this path during runtime, you're going to loose everything when redeploying your application.

    0 讨论(0)
提交回复
热议问题