首页 > 代码库 > ServletContext

ServletContext

一、得到ServletContext的方法

  ServletContext context = this.getServletContext();

二、用途:通过context的getInitParameter()方法获取web.XML中配置的参数

  XML文件:

 <context-param>    <param-name>邮箱</param-name>    <param-value>434507250</param-value>  </context-param>  <context-param>    <param-name>电话号码</param-name>    <param-value>18381330428</param-value>  </context-param>

  Servlet源文件:

  

ServletContext context = this.getServletContext();String email = context.getInitParameter("邮箱");String tel = context.getInitParameter("电话号码");

 

ServletContext