code061.java
package pack01;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
public class code061 implements Filter
{
private int count; // ������Ա����
@Override
public void init(FilterConfig filterConfig) throws ServletException
{
String param = filterConfig.getInitParameter("countx1"); //��web.xml�����ļ���ȡ�ò���ֵ
this.count = Integer.valueOf(param); //��ֵ
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException
{
this.count++;
HttpServletRequest req = (HttpServletRequest)request;
ServletContext context = req.getSession().getServletContext();
context.setAttribute("countx2", this.count);
chain.doFilter(request, response);
}
@Override
public void destroy()
{
}
/*
* ����tomcat��������web.xml�����ļ��а������½�������
*<filter>
* <filter-name>code061</filter-name>
* <filter-class>pack01.code061</filter-class>
* <init-param>
* <param-name>countx1</param-name>
* <param-value>3000</param-value>
* </init-param>
*</filter>
*<filter-mapping>
* <filter-name>code061</filter-name>
* <url-pattern>/page04/code062.jsp</url-pattern>
*</filter-mapping>
*</web-app>
*
*
*
*
*/
}