开发者

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

开发者 https://www.devze.com 2022-12-30 00:18 出处:网络
Why does ServletContext#getRealPath() not return me correct path if i use ../ This code works :- System.out.println(context.getRealPath(\"/\"));

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

精彩评论

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

关注公众号