2

I want to get the real path of a file in java by using the request method getRealPath()but it is deprecated now i want an alternate to it i tried get servletcontext but it is not returning the whole path

in jsp page when i m using application.getRealPath("/") it is giving whole path as D:/.....

but in java servlet code i m not getting this method working so i want a perfect httprequest method which will be returning whole path of the application.

please suggest me a perfect method with example if possible

krishna
  • 179
  • 1
  • 4
  • 13

2 Answers2

6

request.getServletContext().getRealPath(..) (or if you are within a servlet, just call getServletContext().getRealPath(..)

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
  • i am using struts 1 in this i had tried this earlier request.getServletContext is not defined giving error – krishna Oct 18 '10 at 04:15
-1

try this one request.getSession().getServletContext().getRealPath("/");

Satya
  • 1