package demo;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
public class DemoFilter implements Filter
{
private String name=null;
@Override
public void destroy()
{
}
@Override
public void doFilter(ServletRequest arg0, ServletResponse arg1,
FilterChain arg2) throws IOException, ServletException
{
arg0.setAttribute(“name”, “init text string : ” + name);
arg2.doFilter(arg0, arg1);
}
@Override
public void init(FilterConfig arg0) throws ServletException
{
//获得web.xml中filter init-param 中的配置
name=arg0.getInitParameter(“name”);
}
}
package demo;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
public class DemoFilter implements Filter
{
private String name=null;
@Override
public void destroy()
{
}
@Override
public void doFilter(ServletRequest arg0, ServletResponse arg1,
FilterChain arg2) throws IOException, ServletException
{
arg0.setAttribute(“name”, “init text string : ” + name);
arg2.doFilter(arg0, arg1);
}
@Override
public void init(FilterConfig arg0) throws ServletException
{
//获得web.xml中filter init-param 中的配置
name=arg0.getInitParameter(“name”);
}
}
© 版权声明
文章版权归作者所有,未经允许请勿转载。