config 对象
config 对象里存放着一些Servlet 初始的数据结构。
config 对象实现于javax.servlet.ServletConfig 接口,它共有下列四种方法:
public String getInitParameter(name)
public java.util.Enumeration getInitParameterNames( )
public ServletContext getServletContext( )
public Sring getServletName( )
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'config.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<body bgcolor="#ffffff">
<%
int org = 0;
int count = 0;
try
{
org = Integer.parseInt(config.getInitParameter("count").toString());
}
catch(Exception e)
{
out.println("org:"+e);
}
try
{
count = Integer.parseInt(application.getAttribute("config_counter").toString());
}
catch(Exception e)
{
out.println("config_counter"+e);
}
if(count<org)
count = org;
out.println("<br>");
out.println("count is " + count);
out.println("<br>");
out.println("org is "+ org);
out.println("<br>");
out.println("这页面已经访问了"+count+"次");
count++;
application.setAttribute("config_counter",new Integer(count));
%>
</body>
</body>
</html>
The result :
org:java.lang.NullPointerException
count is 14
org is 0
这页面已经访问了14次