首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

getServletContext().getRealPath() 跟request.getRealPath

2012-12-20 
getServletContext().getRealPath() 和request.getRealPath今天开发项目中发现:request.getRealPath(arg0)

getServletContext().getRealPath() 和request.getRealPath

今天开发项目中发现:request.getRealPath(arg0); 报警告:

The method getRealPath(String) from the type ServletRequest is deprecated

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

Deprecated. As of Version 2.1 of the Java Servlet API, use ServletContext.getRealPath(java.lang.String) instead.

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

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

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

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

1 楼 YYang5968 2011-12-24   request.getSession().getServletContext().getRealPath()
这个在struts2里面的action类里可以用, 其他的就不知道了, 没试

热点排行