1、application:javax。servlet。ServletContext的实例,该实例代表JSP所属的web应用 本身,可用于JSP页面,或者在Servlet之间交换信息。常用的方法有getAttribute,setAttribute,getInitParameter等。
2、application对象代表web应用本身,因此使用application来操作web应用相关数据
3、使用application让多个JSP、Servlet共享数据:
A.jsp:
<%! int i;%>
<%application.setAttribute("counter",String.valueOf(++i));%>
Servlet:
ServletContext sc=getServletConfig().getServletContext();
sc.getAttribute("counter");
4、获取web应用配置参数:
jsp:
<% application.getInitParameter("driver");%>
web.xml:
<context-param>
<param-name>driver</param-name>
<param-value>com.mysql.jdbc.Driver</param-value>
</context-param>