|  
 
 
用MyEclipse创建了一个web项目,在web.xml的context-param节点定义数据库的连接信息以及账号密码等,应该怎么读取context-param的值,要引入哪些包,使用getServletContext().getInitParameter,总是提示没有定义方法  你得先把你的配置文件信息贴上来,别人才能帮你分析。     数据库的配置信息一般不会写到web.xml配置文件中,而是写在Properties属性文件内。     导包必须要有javax.servlet.ServletContext;     全局初始化参数配置在<wep-app></web-app>内,的格式如下: <wep-app>   <context-param>    <param-name>参数名</param-name>    <param-value>参数值</param-value>   </context-param>   (其他配置) </web-app> 访问格式: 
ServletContext sctx = getServletContext();//创建ServletContext对象 String 参数值 = sctx.getInitParameter(String 参数名); 一般用户配置都封装在properties文件中, 假如楼主真要存放在web.xml中,那么也可以读取,但是一定要在servlet中 如  public void doGet(HttpServletRequest request, HttpServletResponse response)               throws ServletException, IOException {          String 参数值 = this.getServletContext().getInitParameter("参数名");     }    
 |