如何通过web.xml部署servlet程序 web过滤器的步骤?

[更新]
·
·
分类:互联网
2877 阅读

如何通过web.xml部署servlet程序

web过滤器的步骤?

web过滤器的步骤?

1、新建一个类,实现Filter接口
2、实现doFilter()方法,打印一句话,来证明能够进行拦截
3、在web.xml中进行配置(参照Servlet配置)
4、访问一个页面,看看能不能拦截
1gt
package
import
import
import
import
import
import
import
public class Demo1Filter implements Filter {
tprivate FilterConfig filterConfig
tpublic void doFilter(ServletRequest request, ServletResponse response,
tttFilterChain chain) throws IOException, ServletException {
(#34Demo1过滤前#34)
((#34param1#34))
(request, response)//放行。让其走到下个链或目标资源中
(#34Demo1过滤后#34)
t}
tpublic void init(FilterConfig filterConfig) throws ServletException {
(#34初始化了#34)
filterConfig
t}
tpublic void destroy() {
(#34销毁了#34)
t}
}

conf是什么命令?

conf是配置文件config的简写,多用于存取硬件驱动程序的安装配置信息。
config是Web配置命令,web容器在初始化时使用一个ServletConfig(即config)对象向JSP页面传递信息,此配置信息包括初始化参数(在当前Web应用的应用部署描述文件web.xml中定义)以及表示Servlet或JSP页面所属Web应用的ServletContext对象。