tomcat下的为什么不能使用绝对路径获取文件对象

Tomcat的web项目中springMVC一般不是在ModelAndView中通过相对路径获取jsp对象的吗,为什么new File中不能通过相对路径获取文件对象而要getRealPath()转成绝对路径才行呢,百思不得其解,请大家帮帮忙吧。

 **ModelAndView mav = new ModelAndView("/pages/portal/shareDocument/share_document");**
        //session中获取封装的数据
        ServiceActionContext sc= (ServiceActionContext) request.getSession().getAttribute("ac");
        //判断用户所属的地区,根据地区作为查询条件
        if (sc.getCountyName() != null && sc.getCountyName().length() > 0) {
            tempShareDocList = this.getShareDocumentBO().getFourShareDocumentsByArea(sc.getCountyName());
        }else {
            tempShareDocList = this.getShareDocumentBO().getFourShareDocumentsByArea(sc.getCityName());
        }
        //综合类置顶四条
        **String path = request.getSession().getServletContext().getRealPath("/pages/portal/shareDocument/stack");**
        File fileDoc = new File(path);
        if (fileDoc.exists()) {
            File[] files = fileDoc.listFiles();
            for (File file : files) {
                if(e < 4) {
                    ShareDocument sd = new ShareDocument();
                    sd.setType("综合类");
                    sd.setFileName(file.getName());
                    sd.setSaveAddress("/pages/portal/shareDocument/stack/"+file.getName());
                    shareDocList.add(sd);
                    e++;
                }
            }
        }

TOMCAT启动的时候,是将工程重新编译放在tomcat中执行的,它的目录结构也会随之发生改变。这时候不管是相对路径还是绝对路径都有可能出错。
这边看下这个文章描述。
https://blog.csdn.net/zhangka002/article/details/55049494