Reputation: 1378
I am working on web application.I invoke on my jsp request.getContextPath()
, but strangely I got address /streetshop
.
Then I am appending some path as request.getContextPath() + "abc"
and create folder.
Then its creating folder in D://
instead of my webapplication folder.
Please, tell me, I want to upload an image in put it in my web-application root/images/images.gif
.
Upvotes: 3
Views: 16582
Reputation: 12538
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.
Upvotes: 12