servletcontext的作用

回答
爱扬教育

2022-02-13

  • 相关推荐
作用:
可以读取全局配置参数;
可以搜索当前工程目录下面的资源文件;
可以获取当前工程名字。
ServletContext.getContext().getxx() 一般是引用上下文路径。

扩展资料

  servletcontext的用法:

  1、ServletContext对象获取

  this.getServletContext();

  this.getServletConfig().getServletContext();

  2、添加属性:setAttribute(String name, Object obj);

  3、得到值:getAttribute(String name),这个方法返回Object

  4、删除属性:removeAttribute(String name)