当前位置:网站首页>Filter过滤器解决request请求参数乱码的原理解析
Filter过滤器解决request请求参数乱码的原理解析
2022-07-25 10:35:00 【努力的clz】
本篇文章是对SpringMVC出现request请求参数乱码情况解决办法博客中“解决措施1”的原理解析,个人认为了解一些简单技术背后的原理对个人编程还是挺有帮助的。
如果有request请求参数乱码问题的小伙伴可以去查看下我上面提到的那片博客,希望对大家有所帮助!
1、进入CharacterEncodingFilter.class

2、CharacterEncodingFilter继承结构图
可以看出CharacterEncodingFilter的曾祖父居然是Filter


3、doFilter( )方法
我们重点看Filter接口的doFilter( )方法的实现情况:
doFilter( )方法在OncePerRequestFilter里实现:
关键:doFilter( )方法里执行了doFilterInternal( ),而doFilterInternal( )方法的实现又在OncePerRequestFilter的子类CharacterEncodingFilter里实现。
绕了一圈又回到了CharacterEncodingFilter类了,看下关键代码:
4、回顾下web.xml里的配置信息

5、CharacterEncodingFilter类中的属性
查看源代码,CharacterEncodingFilter类有三个属性,并且发现无论有参还是无参构造方法forceRequestEncoding、
forceResponseEncoding这两个属性的初始值都是false。下面的主要目的就是解释为什么要改成ture?
6、关键代码

1、我们在web.xml里设置了encoding为UTF-8,所以该值不为空。
2、我们在web.xml里设置了forceRequestEncoding、forceResponseEncoding两个Boolean值为true,所以if语句可以执
行。
3、分别将request、response的编码设置成encoding,也就是UTF-8。
到此,分析结束!
边栏推荐
- MLX90640 红外热成像仪测温模块开发笔记(五)
- Learn Luzhi PHP -- tp5.0 uses Chinese as an alias and reports "unsupported data expression"
- 常见的几种PCB表面处理技术!
- 使用Three.js实现炫酷的赛博朋克风格3D数字地球大屏
- 学习路之PHP--Phpstudy 提示 Mysqld.Exe: Error While Setting Value ‘NO_ENGINE_SUBSTITUTION 错误的解决办法
- LVS负载均衡之LVS-NAT搭建Web群集
- B2B2C多商户系统功能丰富,极易二开!!!
- Multiply Floyd "suggestions collection"
- How can you use unity without several plug-ins? Unity various plug-ins and tutorial recommendations
- SQL language (III)
猜你喜欢

Hcip experiment (01)

C# Newtonsoft. Jason advanced usage

用Unity不会几个插件怎么能行?Unity各类插件及教程推荐

Learn NLP with Transformer (Chapter 5)

HCIA experiment (07) comprehensive experiment
Definition of information entropy
苹果美国宣布符合销售免税假期的各州产品清单细节

基于MATLAB的常见线性调制方法

从宏观到微观 零基础 详解bert

Activity registration | play with kubernetes container service improvement class officially opened!
随机推荐
B2B2C多商户系统功能丰富,极易二开!!!
只知道预制体是用来生成物体的?看我如何使用Unity生成UI预制体
PostgreSQL踩坑 | ERROR: operator does not exist: uuid = character varying
玩游戏想记录一下自己超神的瞬间?那么就来看一下如何使用Unity截图吧
全网显示 IP 归属地,是怎么实现的?
Loadbalancerlife lifecycle requested by feign client
Implementation of recommendation system collaborative filtering in spark
数据库设计-简化字典表[通俗易懂]
HCIA experiment (06)
Details of the list of state products that Apple announced to be eligible for the sales tax holiday in the United States
Let sports happen naturally, and fire creates a new lifestyle
syncronized锁升级的过程
Txt to CSV file, blank lines appear every other line
为什么重写equals()方法必须要重写hashCode()方法
Learn NLP with Transformer (Chapter 6)
常见的几种PCB表面处理技术!
大话DevOps监控,团队如何选择监控工具?
Hcip experiment (02)
复习背诵整理版
tensorflow 调用多块GPU的一些错误