views:

59

answers:

1

Hello, Why does ServletContext#getRealPath() not return me correct path if i use ../

This code works :-

System.out.println(context.getRealPath("/"));

This one doesn't :-

System.out.println(context.getRealPath("/.."));

How can i get one level up directory from getRealPath()?

+2  A: 

Why does ServletContext#getRealPath() not return me correct path if i use "../":

To help protect you against requests that use ".." tricks to fetch content that they are not supposed to see; e.g. something like "../../../../../etc/passwd".

If you want to refer to a directory outside of the servlet context, you will need to create the path another way.

Stephen C