1.在web.xml中加入一个过滤器和过滤范围的配置

<filter>
<filter-name>encoding</filter-name>
<filter-class>com.guet.cab.base.Filter.EncodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

2.com.guet.cab.base.Filter.EncodingFilter指明其具体实现的包名,第二个配置指明其监听所有的请求。

3.字符编码过滤的具体实现为

package com.guet.cab.base.Filter;

import java.io.*;
import javax.servlet.*;

public class EncodingFilter implements Filter {
public void init(FilterConfig filterConfig) throws ServletException {

}

public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
try {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
} catch (Exception e) {
}

chain.doFilter(request, response);
}

public void destroy() {

}
};

1.在web.xml中加入一个过滤器和过滤范围的配置

<filter>
<filter-name>encoding</filter-name>
<filter-class>com.guet.cab.base.Filter.EncodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

2.com.guet.cab.base.Filter.EncodingFilter指明其具体实现的包名,第二个配置指明其监听所有的请求。

3.字符编码过滤的具体实现为

package com.guet.cab.base.Filter;

import java.io.*;
import javax.servlet.*;

public class EncodingFilter implements Filter {
public void init(FilterConfig filterConfig) throws ServletException {

}

public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
try {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
} catch (Exception e) {
}

chain.doFilter(request, response);
}

public void destroy() {

}
};

 

SSH中设置字符编码防止乱码的更多相关文章

  1. ecplise中设置字符编码

    ecplise 设置 1 ecplise编码格式 右键 在general-workspace- text file encoding 选择utf-8 2 jsp文件编码格式 web-jspfile-e ...

  2. 黄聪:wordpress在IIS8中设置默认编码(windows2012服务器)

    web.config中配置 <?xml version="1.0" encoding="UTF-8"?> <configuration> ...

  3. SpringBoot(八):SpringBoot中配置字符编码 Springboot中文乱码处理

    SpringBoot中配置字符编码一共有两种方式 方式一: 使用传统的Spring提供的字符编码过滤器(和第二种比较,此方式复杂,由于时间原因这里先不介绍了,后续补上) 方式二(推荐使用) 在appl ...

  4. 浅析白盒审计中的字符编码及SQL注入

    尽管现在呼吁所有的程序都使用unicode编码,所有的网站都使用utf-8编码,来一个统一的国际规范.但仍然有很多,包括国内及国外(特别是非英语国家)的一些cms,仍然使用着自己国家的一套编码,比如g ...

  5. APACHE2.4 指定目录中的字符编码

    APACHE2.4 指定目录中的字符编码 xampp 的 apache2.4 默认字符编码是西文,中文字符显示乱码,在 httpd.conf 没有 AddDefaultCharset utf-8 这样 ...

  6. 001. Java内存中的字符编码

    Java内存中的字符编码 Unicode字符集及utf-8 .utf-16.utf-32 等字符编码方式 字符集:字符表示的数字集合,元素称为码点或码位: 字符编码:字符实际的储存表示: 码点:一个码 ...

  7. web.xml 设置字符编码

    个人理解  就是为了防止在前端输入的数据到了后台发生乱码 直接复制到web.xml里面就可以使用 亲测 能用!!! <!-- 前端过滤器设置字符编码 --> <filter> ...

  8. MySQL基础配置之mysql的默认字符编码的设置(my.ini设置字符编码) - 转载

    MySQL基础配置之mysql的默认字符编码的设置(my.ini设置字符编码) MySQL的默认编码是Latin1,不支持中文,那么如何修改MySQL的默认编码呢,下面以设置UTF-8为例来说明. 需 ...

  9. Java工具类-设置字符编码

    package common; import java.io.IOException; import javax.servlet.Filter; import javax.servlet.Filter ...

随机推荐

  1. break、continue、pass介绍

    break.continue.pass介绍 break:跳出当前循环 continue:跳出本次循环,进行下一次循环 pass:什么也不做,占位.

  2. fio 测试磁盘

    root@rook-test:/# ceph osd status+----+-----------------------------+-------+-------+--------+------ ...

  3. Ansible test

    [root@localmesos ansible_test]# ansible all -a "/bin/echo hello"192.168.111.111 | SUCCESS ...

  4. sdc docker连接

    curl -O https://raw.githubusercontent.com/joyent/sdc-docker/master/tools/sdc-docker-setup.sh &&a ...

  5. WebDriverException:Element is not clickable at point - selenium执行过程中遇到的相关报错

    Element is not clickable at point (x, y) 这段可以忽略:本文来自 https://www.cnblogs.com/lozz/p/9947430.html 引起这 ...

  6. git的一些常用操作命令

    这些操作命令都是从廖雪峰老师的官网上看过后记下来的,以下是廖雪峰老师的官网,大家可以看看,教程不错~ http://www.liaoxuefeng.com/wiki/00137395163059296 ...

  7. web程序的配置文件的修改

    vs上面的config与wwwroot中的config有可能不一样,注意修改配置的资源路径及ip及数据库及禁止ip

  8. input上传图片

    1.通过input自身的onchange事件触发: <input id="file" type="file" accept="image/*&q ...

  9. .NET中的文件IO操作实例

    1.写入文件代码: //1.1 生成文件名和设置文件物理路径 Random random = new Random(DateTime.Now.Millisecond); ); string Physi ...

  10. pymysql基本的使用方法

    1.导入模块+创建连接 import pymysql # 1.通过python去连接数据库 conn = pymysql.connect(host="127.0.0.1",port ...