普通java类获取request并获取发布项目所在的物理路径

普通java类获取request并获取发布项目所在的物理路径   

http://rainbowdesert.iteye.com/blog/1977979

       博客分类:

 

 

Java代码 复制代码 收藏代码
  1. ActionContext ac = ActionContext.getContext();   
  2. HttpServletRequest request = (HttpServletRequest)ac.get(ServletActionContext.HTTP_REQUEST);  
ActionContext ac = ActionContext.getContext(); 
HttpServletRequest request = (HttpServletRequest)ac.get(ServletActionContext.HTTP_REQUEST);

 

Java代码 复制代码 收藏代码
  1. /*************************************************************************** 
  2.  * 函数名:getPath 作 用:获取服务器路径 参 数:request 返回值:字符串 
  3.          * By goodadd  
  4.  **************************************************************************/  
  5. public String getPath(javax.servlet.http.HttpServletRequest request) {  
  6.     //String basePath = "/WEB-INF/classes/";  
  7.     String path = request.getSession().getServletContext().getRealPath(basePath);  
  8.     path = path.replace("/", "\\");  
  9.     return path + "\\";  
  10. }  
	/***************************************************************************
	 * 函数名:getPath 作 用:获取服务器路径 参 数:request 返回值:字符串
          * By goodadd 
	 **************************************************************************/
	public String getPath(javax.servlet.http.HttpServletRequest request) {
		//String basePath = "/WEB-INF/classes/";
		String path = request.getSession().getServletContext().getRealPath(basePath);
		path = path.replace("/", "\\");
		return path + "\\";
	}

 

 

posted @ 2017-08-16 20:36  sky20080101  阅读(212)  评论(0编辑  收藏  举报