jsp filter 过滤器功能与简单用法示例(js中filter过滤对象)这都可以?

随心笔谈11个月前发布 admin
88 0


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”);
}
}

© 版权声明

相关文章