当前位置:网站首页>JSP response,request操作中(中文乱码)-如何解决呢?
JSP response,request操作中(中文乱码)-如何解决呢?
2022-07-31 08:23:00 【qq_25073223】
转自:
JSP response,request操作中(中文乱码)-如何解决呢?
下文讲述response,request操作中中文乱码的处理方法分享,如下所示:
当request向服务器发送中文字符时,服务器端获取的乱码 当response向客户端发送中文字符时,客户端接收到的是乱码, 我们在开发中遇到这种问题,就是request,response乱码,那么如何处理此类异常
response中文乱码的处理方法
服务器发给浏览器的数据默认是按照ISO-8859-1编码
浏览器接收到数据后按照默认的字符集进行解码后显示
如果浏览器的默认解码字符集不是ISO-8859-1,就出现乱码
处理方法: 设置服务器端编码和客户端编码一致 ------------------------------------------------ 1.设置服务器端的编码 response.setCharacterEncoding('utf-8”); 2.通知浏览器服务器发送的数据格式 response.setContentType('text/html;charset=utf-8”); 3.jsp页面通知浏览器展示的编码格式 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
request中文乱码的处理方法
处理方法: 1.无论get请求还是post请求,将中文参数进行url编码,用URLEncoder.encode()进行编码传到后台 2.设置pageEncoding=“utf-8” 3.后台接收编码也用 utf-8 4.web.xml设置编码 <filter> <filter-name>encodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
边栏推荐
猜你喜欢
如何在 Linux 上安装 MySQL
刷题《剑指Offer》day05
[Mini Program Project Development--Jingdong Mall] Custom Search Component of uni-app (Middle)--Search Suggestions
云服务器部署 Web 项目
MySQL 8.0.29 解压版安装教程(亲测有效)
【MySQL中auto_increment有什么作用?】
35-Jenkins-共享库应用
科目三:前方路口直行
XSS详解
Open Source | Commodity Recognition Recommender System
随机推荐
Vulkan与OpenGL对比——Vulkan的全新渲染架构
日志导致线程Block的这些坑,你不得不防
免安装版的Mysql安装与配置——详细教程
【MySQL中auto_increment有什么作用?】
[MySQL exercises] Chapter 4 · Explore operators in MySQL with kiko
"C language" frog jumping steps recursion problem
2019 NeurIPS | Graph Convolutional Policy Network for Goal-Directed Molecular Graph Generation
[Cloud native and 5G] Microservices support 5G core network
高并发-高可用-高性能
ScheduledExecutorService - 定时周期执行任务
sqlmap使用教程大全命令大全(图文)
[Mini Program Project Development--Jingdong Mall] Custom Search Component of uni-app (Middle)--Search Suggestions
[MySQL exercises] Chapter 3 Common data types in MySQL
【黄啊码】MySQL入门—3、我用select ,老板直接赶我坐火车回家去,买的还是站票
Unreal基础概念
【MySQL功法】第3话 · MySQL中常见的数据类型
【Unity】编辑器扩展-04-拓展Scene视图
XSS详解
SQL join table (inner join, left join, right join, cross join, full outer join)
力扣 593. 有效的正方形