在一个普通的java类中,如何传递进去一个servletContext参数啊?   
其中这个类在spring中定义的
<bean id="appUtil" class="com.htsoft.core.util.AppUtil" init-method="init"/>  在appUtil 里有一个init()函数,我想在该函数中使用servletContext.getRealPath()请问大家我如何获得servletContext啊?
  

解决方案 »

  1.   

    spring框架的思路, 在WEB-INF/web.xml中 , 创建一个webAppRootKey的param, 指定一个值(默认为webapp.root)作为键值, 然后通过Listener , 或者Filter , 或者Servlet 执行String webAppRootKey = getServletContext().getRealPath("/"); 并将webAppRootKey对应的webapp.root 分别作为Key , Value写到System Properties系统属性中。之后在程序中通过System.getProperty("webapp.root")来获得WebRoot的物理路径。这个是网上看来的。