java上下文绝对路径

来源:互联网 发布:mblock编程推箱子 编辑:程序博客网 时间:2024/06/08 09:08
 三种方法

一:

HttpServletRequest request = ServletActionContext.getRequest();  

String path= request.getSession().getServletContext().getRealPath("//");  

 二:

public void init(FilterConfig config) throws ServletException {  

  String contextPath = config.getServletContext().getRealPath("//");  

 }  

三:

String contextPath = request.getScheme()+"://"+request.getServerName()    +":"+request.getServerPort()+request.getContextPath()+"/";  

原创粉丝点击