博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
过滤器的使用
阅读量:5072 次
发布时间:2019-06-12

本文共 2268 字,大约阅读时间需要 7 分钟。

代码

package cn.itcast.filter;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;import javax.servlet.annotation.WebFilter;public class DemoFilter implements Filter {    public DemoFilter() {    }    public void destroy() {    }    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {        // TODO Auto-generated method stub        // place your code here        request.setCharacterEncoding("UTF-8");        response.setCharacterEncoding("UTF-8");        System.out.println("这是自定义过滤器,设置字符编码集为UTF-8");        // pass the request along the filter chain        chain.doFilter(request, response);    }    /**     * @see Filter#init(FilterConfig)     */    public void init(FilterConfig fConfig) throws ServletException {        // TODO Auto-generated method stub        System.out.println("init: 初始化方法。。。");    }}
package com.demo.servlet;import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;/** * Servlet implementation class DemoServlet */@WebServlet("/DemoServlet")public class DemoServlet extends HttpServlet {    private static final long serialVersionUID = 1L;    /**     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)     */    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {                        response.getWriter().append("这是经过过滤之后的输出");    }    /**     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)     */    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        // TODO Auto-generated method stub        doGet(request, response);    }}

 

 将代码注释掉

 

 过滤之前的情况

 

 然后去掉注释

 

链接:https://pan.baidu.com/s/1rXs_3NdMVKteQKyLP6ao8g

提取码:5ko3
复制这段内容后打开百度网盘手机App,操作更方便哦

 

转载于:https://www.cnblogs.com/cappu-ccino/p/10742922.html

你可能感兴趣的文章
移动端页面开发适配 rem布局原理
查看>>
Ajax中文乱码问题解决方法(服务器端用servlet)
查看>>
会计电算化常考题目一
查看>>
阿里云服务器CentOS6.9安装Mysql
查看>>
剑指offer系列6:数值的整数次方
查看>>
js 过滤敏感词
查看>>
poj2752 Seek the Name, Seek the Fame
查看>>
软件开发和软件测试,我该如何选择?(蜗牛学院)
查看>>
基本封装方法
查看>>
bcb ole拖拽功能的实现
查看>>
生活大爆炸之何为光速
查看>>
bzoj 2456: mode【瞎搞】
查看>>
[Typescript] Specify Exact Values with TypeScript’s Literal Types
查看>>
[GraphQL] Reuse Query Fields with GraphQL Fragments
查看>>
Illustrated C#学习笔记(一)
查看>>
理解oracle中连接和会话
查看>>
两种最常用的Sticky footer布局方式
查看>>
Scrapy实战篇(三)之爬取豆瓣电影短评
查看>>
HDU 5510 Bazinga KMP
查看>>
[13年迁移]Firefox下margin-top问题
查看>>