0

This is the statement:

System.out.println("getServletContext : " + request.getServletContext().getRealPath(File.separator));

Output:

getServletContext : null

This is the statement:

System.out.println(request.getServletContext());

Output:

org.apache.catalina.core.ApplicationContextFacade@1cb0b163

I need the actual file path, because I need to upload my files inside the application directory.

BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
  • Did you look at [this](https://stackoverflow.com/questions/536228/why-does-getrealpath-return-null-when-deployed-with-a-war-file)? Don't use getRealPath method. – SMA Jul 29 '18 at 12:06
  • Do you save your Word or Excel documents into the installation directory of Office? No. For good reasons: these are data, that don't belong there. And you really don't want all these documents to dsappear if you reinstall Office. Same here: uploaded data do NOT belong to the application directory. Not to mention that you could even not have any directory at all if you deploy a war file. – JB Nizet Jul 29 '18 at 12:41
  • Yeah that's true. But then where to upload my files? Please give me some more idea about it. – Somnath Sadhu Jul 29 '18 at 17:09
  • And sorry. I said application directory. My mistake. I meant my project directory. The directory which will be created from my war file. Is that folder alright? Or should I save my files in a folder outside my project directory? @JBNizet – Somnath Sadhu Jul 29 '18 at 17:11
  • If it's created from your war file, it will be deleted and recreated when you redeploy the app, every time you fix some bug and make a new release. Changing the name of that folder from "application directory" to "project directory" doesn't change anything. You should save your files **outside** of this directory. – JB Nizet Jul 29 '18 at 17:15
  • @SMA It worked with "/". Previously I was using File.separator. And I tested it on my web server as well after deploying my war file. Files are getting uploaded. – Somnath Sadhu Jul 29 '18 at 17:18
  • Ok. Thanks for the info @JBNizet – Somnath Sadhu Jul 29 '18 at 17:25

0 Answers0