问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

fitter 如何只过滤jsp

发布网友 发布时间:2023-07-26 05:37

我来回答

1个回答

热心网友 时间:2023-09-17 17:43

Servlet过滤器开发步骤开发Servlet过滤器的步骤如下:①编写实现Filter接口的Servlet类。②在web.xml中配置Filter。开发一个过滤器需要实现Filter接口,Filter接口定义了以下方法:①destory()由Web容器调用,初始化此Filter。②init(FilterConfig filterConfig)由Web容器调用,初始化此Filter。③doFilter(ServletRequest request,ServletResponse response,FilterChain chain)具体过滤处理代码。3.一个过滤器框架实例SimpleFilter1.java
package com.zj.sample;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 SimpleFilter1 implements Filter { @SuppressWarnings("unused") private FilterConfig filterConfig; public void init(FilterConfig config) throws ServletException { this.filterConfig = config; } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) { try { System.out.println("Within SimpleFilter1:Filtering the Request..."); chain.doFilter(request, response);// 把处理发送到下一个过滤器 System.out .println("Within SimpleFilter1:Filtering the Response..."); } catch (IOException ioe) { ioe.printStackTrace(); } catch (ServletException se) { se.printStackTrace(); } } public void destroy() { this.filterConfig = null; }}
SimpleFilter2.java
package com.zj.sample;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 SimpleFilter2 implements Filter { @SuppressWarnings("unused") private FilterConfig filterConfig; public void init(FilterConfig config) throws ServletException { this.filterConfig = config; } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) { try { System.out.println("Within SimpleFilter2:Filtering the Request..."); chain.doFilter(request, response); // 把处理发送到下一个过滤器 System.out.println("Within SimpleFilter2:Filtering the Response..."); } catch (IOException ioe) { ioe.printStackTrace(); } catch (ServletException se) { se.printStackTrace(); } } public void destroy() { this.filterConfig = null; }}
web.xml
<filter> <filter-name>filter1</filter-name> <filter-class>com.zj.sample.SimpleFilter1</filter-class></filter><filter-mapping> <filter-name>filter1</filter-name> <url-pattern>/*</url-pattern>//为所有的访问做过滤</filter-mapping> <filter> <filter-name>filter2</filter-name> <filter-class>com.zj.sample.SimpleFilter2</filter-class></filter><filter-mapping> <filter-name>filter2</filter-name> <url-pattern>/*</url-pattern>//为所有的访问做过滤</filter-mapping>
打开web容器中任意页面输出结果:(注意过滤器执行的请求/响应顺序)
Within SimpleFilter1:Filtering the Request...
Within SimpleFilter2:Filtering the Request...
Within SimpleFilter2:Filtering the Response...
Within SimpleFilter1:Filtering the Response...
4.报告过滤器我们来试验一个简单的过滤器,只要调用相关的servlet或JSP页面,它就打印一条消息到标准输出。为实现此功能,在doFilter方法中执行过滤行为。每当调用与这个过滤器相关的servlet或JSP页面时,doFilter方法就生成一个打印输出,此输出列出请求主机和调用的URL。因为getRequestURL方法位于HttpServletRequest而不是ServletRequest中,所以把ServletRequest对象构造为HttpServletRequest类型。我们改动一下章节3的SimpleFilter1.java。SimpleFilter1.java
package com.zj.sample;import java.io.IOException;import java.util.Date;import javax.servlet.Filter;import javax.servlet.FilterChain;import javax.servlet.FilterConfig;import javax.servlet.ServletException;import javax.servlet.ServletRequest;import javax.servlet.ServletResponse;import javax.servlet.http.HttpServletRequest; public class SimpleFilter1 implements Filter { @SuppressWarnings("unused") private FilterConfig filterConfig; public void init(FilterConfig config) throws ServletException { this.filterConfig = config; } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) { try { System.out.println("Within SimpleFilter1:Filtering the Request..."); HttpServletRequest req = (HttpServletRequest) request; System.out.println(req.getRemoteHost() + " tried to access " + req.getRequestURL() + " on " + new Date() + "."); chain.doFilter(request, response); System.out.println("Within SimpleFilter1:Filtering the Response..."); } catch (IOException ioe) { ioe.printStackTrace(); } catch (ServletException se) { se.printStackTrace(); } } public void destroy() { this.filterConfig = null; }}
web.xml设置不变,同章节3。

热心网友 时间:2023-09-17 17:43

Servlet过滤器开发步骤开发Servlet过滤器的步骤如下:①编写实现Filter接口的Servlet类。②在web.xml中配置Filter。开发一个过滤器需要实现Filter接口,Filter接口定义了以下方法:①destory()由Web容器调用,初始化此Filter。②init(FilterConfig filterConfig)由Web容器调用,初始化此Filter。③doFilter(ServletRequest request,ServletResponse response,FilterChain chain)具体过滤处理代码。3.一个过滤器框架实例SimpleFilter1.java
package com.zj.sample;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 SimpleFilter1 implements Filter { @SuppressWarnings("unused") private FilterConfig filterConfig; public void init(FilterConfig config) throws ServletException { this.filterConfig = config; } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) { try { System.out.println("Within SimpleFilter1:Filtering the Request..."); chain.doFilter(request, response);// 把处理发送到下一个过滤器 System.out .println("Within SimpleFilter1:Filtering the Response..."); } catch (IOException ioe) { ioe.printStackTrace(); } catch (ServletException se) { se.printStackTrace(); } } public void destroy() { this.filterConfig = null; }}
SimpleFilter2.java
package com.zj.sample;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 SimpleFilter2 implements Filter { @SuppressWarnings("unused") private FilterConfig filterConfig; public void init(FilterConfig config) throws ServletException { this.filterConfig = config; } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) { try { System.out.println("Within SimpleFilter2:Filtering the Request..."); chain.doFilter(request, response); // 把处理发送到下一个过滤器 System.out.println("Within SimpleFilter2:Filtering the Response..."); } catch (IOException ioe) { ioe.printStackTrace(); } catch (ServletException se) { se.printStackTrace(); } } public void destroy() { this.filterConfig = null; }}
web.xml
<filter> <filter-name>filter1</filter-name> <filter-class>com.zj.sample.SimpleFilter1</filter-class></filter><filter-mapping> <filter-name>filter1</filter-name> <url-pattern>/*</url-pattern>//为所有的访问做过滤</filter-mapping> <filter> <filter-name>filter2</filter-name> <filter-class>com.zj.sample.SimpleFilter2</filter-class></filter><filter-mapping> <filter-name>filter2</filter-name> <url-pattern>/*</url-pattern>//为所有的访问做过滤</filter-mapping>
打开web容器中任意页面输出结果:(注意过滤器执行的请求/响应顺序)
Within SimpleFilter1:Filtering the Request...
Within SimpleFilter2:Filtering the Request...
Within SimpleFilter2:Filtering the Response...
Within SimpleFilter1:Filtering the Response...
4.报告过滤器我们来试验一个简单的过滤器,只要调用相关的servlet或JSP页面,它就打印一条消息到标准输出。为实现此功能,在doFilter方法中执行过滤行为。每当调用与这个过滤器相关的servlet或JSP页面时,doFilter方法就生成一个打印输出,此输出列出请求主机和调用的URL。因为getRequestURL方法位于HttpServletRequest而不是ServletRequest中,所以把ServletRequest对象构造为HttpServletRequest类型。我们改动一下章节3的SimpleFilter1.java。SimpleFilter1.java
package com.zj.sample;import java.io.IOException;import java.util.Date;import javax.servlet.Filter;import javax.servlet.FilterChain;import javax.servlet.FilterConfig;import javax.servlet.ServletException;import javax.servlet.ServletRequest;import javax.servlet.ServletResponse;import javax.servlet.http.HttpServletRequest; public class SimpleFilter1 implements Filter { @SuppressWarnings("unused") private FilterConfig filterConfig; public void init(FilterConfig config) throws ServletException { this.filterConfig = config; } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) { try { System.out.println("Within SimpleFilter1:Filtering the Request..."); HttpServletRequest req = (HttpServletRequest) request; System.out.println(req.getRemoteHost() + " tried to access " + req.getRequestURL() + " on " + new Date() + "."); chain.doFilter(request, response); System.out.println("Within SimpleFilter1:Filtering the Response..."); } catch (IOException ioe) { ioe.printStackTrace(); } catch (ServletException se) { se.printStackTrace(); } } public void destroy() { this.filterConfig = null; }}
web.xml设置不变,同章节3。
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
13岁一直到18岁晚上经常熬夜会有什么影响 具象表现素描内容简介 ...| 从14世纪文艺复兴到20世纪具象表现绘画 · 168幅画 · 图解西方... 【漫画赏析】比喻具象化——《孤高之人》手法分析 具象美术作品有哪些 具象艺术艺术家介绍 话说 曾经有个演唱会 是初音未来演唱会 39祭 谁知道微信聊天记录删掉了,还能恢复过来吗?有什么软件可以恢复吗?不... 六爻。测缘分。测婚姻 礼仪起源于祭祀的证据是什么? 小生请教前辈一个英语问题 I&#39;d like to get into the school basketball team,t 今年妈妈的年龄是琳琳的7倍五年后妈妈比琳琳大24岁今年妈妈和琳琳各多... ...明明年龄的7倍。妈妈今年多少岁?再过两年,妈妈的年龄是明明的... 妈妈的年龄是明明的7倍,4年后,妈妈的年龄是明明的4倍。明明今年多大了... 今年明明妈妈的年龄是明明的 7倍,妈妈比明明大30岁,多少年后妈妈的年龄... 妈妈今年28岁,妈妈的年龄是明明的7倍今年明明天多少岁?(请画出线段图... 明明今年4岁,妈妈的年龄是明明的7倍、今年妈妈多少岁?再过2年,妈妈的... 明明今年4岁,妈妈的年龄是明明的7倍,妈妈今年多少岁?再过2年,妈妈的年... 今年明明妈妈的年龄是明明的七倍,妈妈比明明大30岁,多少年以后妈妈的年... 妈妈今年28岁,妈妈的年龄是明明的7倍。明明今年几岁? 明明今年4岁,妈妈的年龄是明明的7倍,(1)今年妈妈多少岁?(2)再过两年... ...过河20篇中的一个句子理解有问题(这里理解的动词为啥要用ing... 开专票需要提供一般纳税人证明吗 我在联通网上营业厅买了充值卡后,在哪儿可以查询充值的情况啊?_百度知 ... ...邮箱里没有看到任何东西,我买的充值卡去哪了? 怎么样查询充值卡冲到那里了 如何把全网通话费充值卡的钱充如手机 年轮3删除文件能找回吗? 以光的衍射和干涉现象照射标本,产生明暗不同的反差进行识别,有助辨别... During the summer holidays,Danny went to the Fitness Camp.He m... 蝙蝠为什么怕人? 蝙蝠为什么听不到回声,却能够发现人? 宜春阳光保险集团是国企吗 宜春通达路桥建设有限公司是国企吗 银行卡涉税是什么意思 运城科目四考场有哪几个考场 佛山安全教育平台登陆入口 佛山春季义务教育退费什么时候退 华图教育那么大,能帮忙给点内部免费的资料吗 怎样才能拜入茅山派学习法术 在文玩工作室上班是一件怎样的感受,我来告诉 能看见一个人有几个看另一个聊天记录 K1558在常州北站下车还是在北广场下车 k1558正晚点查询我买到衡阳到站的票,但我想在祁东下车,不知在祁东能... 南宁到无锡,21:55k1558车次在南宁哪个火车站坐车啊? 从广西南宁去江西宜村怎么走铁路线乘火车。 ...侧脑室后角旁白质及半卵圆中心见斑片状长t2信号,t2flair序列呈稍高... 右侧侧脑室后角旁可见斑点状长T1T2信号灶 果丹皮吃了有什么用 果丹皮有什么禁忌