request.getRealPath()的替代方法

 

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

在Servlet 和Struts中还可以用

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

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

ServletActionContext.getServletContext().getRealPath("comm");

  • ActionContext ac = ActionContext.getContext();   
  • ServletContext sc = (ServletContext) ac.get(ServletActionContext.SERVLET_CONTEXT);   
  • String path = sc.getRealPath("/");  
  • request.getContextPath().toString(); 相对路径
posted @ 2014-07-28 14:10  Dhyanas  阅读(314)  评论(0编辑  收藏  举报