ServletContext获取项目真实路径

import javax.servlet.ServletContext;

import org.springframework.web.context.ServletContextAware;

/**
 * @author Administrator
 *
 */
public class PayUtil implements ServletContextAware{

    public ServletContext context ;
    public static String PATH = "";
    /* (non-Javadoc)
     * @see org.springframework.web.context.ServletContextAware#setServletContext(javax.servlet.ServletContext)
     */
    public void setServletContext(ServletContext context) {
        this.context = context;
    }
    
    public void myinit(){
        PayUtil.PATH = context.getRealPath("");
    }    
}

PayUtil.PATH = D:\work\apache-tomcat-7.0.52\webapps\pra

posted on 2015-07-24 09:01  Simle  阅读(967)  评论(0编辑  收藏  举报