开发者

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("/"));

开发者_JAVA百科

This one doesn't :-

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

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜