定义
// import javax.servlet.ServletContext;
// ServletContext类:用于表示应用程序的上下文
// 取得application对象
ServletContext application = this.getServletContext();
或者
ServletContext application = request.getSession().getServletContext();

application对象的常用方法
方法名 描述
String getAttribute(String name) // 根据属性名称获取属性值。
Enumeration getAttributeNames() // 获取所有的属性名称。
void setAttribute(String name, Object object) // 设置属性,指定属性名称和属性值。
void removeAttribute(String name) // 根据属性名称删除对应的属性。
ServletContext getContext(String uripath) // 获取指定URL的ServletContext对象。
String getContextPath() // 获取当前Web应用程序的根目录。
String getInitParameter(String name) // 根据初始化参数名称,获取初始化参数值。
int getMajorVersion() // 获取Servlet API的主版本号。
int getMinorVersion() // 获取Servlet API的次版本号。
String getMimeType(String file) // 获取指定文件的MIME 类型。
String getServletInfo() // 获取当前Web服务器的版本信息。
String getServletContextName() // 获取当前Web应用程序的名称。
void log(String message) // 将信息写入日志文件中。

相关文章:

  • 2021-08-01
  • 2021-09-30
  • 2022-03-07
  • 2022-02-24
  • 2022-12-23
  • 2021-08-07
  • 2021-11-24
  • 2022-12-23
猜你喜欢
  • 2022-02-07
  • 2022-12-23
  • 2021-04-22
  • 2021-05-25
相关资源
相似解决方案