天天看点

request.getRealPath 过期解决

例子: 

String fileUrl = request.getSession().getServletContext().getRealPath("/upload")+"/stafftemplate.xls"; 



request.getRealPath("") 这个方法已经不推荐使用了,那代替它的是什么方法呢? 


下面就是替代它的方法: 


request.getSession().getServletContext().getRealPath() 得到站点的绝对地址 


在servlet或者struts中还可以这样: 


this.getServletContext().getRealPath("/"); 


this.getServlet().getServletContext().getRealPath("/");      

继续阅读