jsp小结08 - 9个内置对象01 application

application:

javax.servlet.ServletContext的实例,代表web应用本身

通过application的setAttribute(String attrName , Object value)方法将值设为application范围内的属性,该属性在整个web应用内有效

在jsp中访问

<%=application.getAttribute(attrName)%>

在Servlet中访问

ServletContext sc = getServletConfig().getServletContext();
sc.getAttribute(attrName);

获得web应用配置参数

web.xml配置

<context-param>
<param-name>driver</param-name>
<param-value>com.mysql.jdbc.Driver</param-value>
</context-param>

获取配置参数

String driver = application.getInitParameter("driver");

你可能感兴趣的:(jsp,Web应用)