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++;
}
}
}