TCM
TCM

Reputation: 16900

ServletContext not giving me real path when i want to go up level directory up

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()?

Upvotes: 0

Views: 724

Answers (1)

Stephen C
Stephen C

Reputation: 718708

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.

Upvotes: 2

Related Questions