场景:
基本所有地方都设置为utf-8
页面中
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
httpResponse.setCharacterEncoding(encoding); // encoding为utf-8
httpResponse.setContentType("text/html; charset=utf-8");<filter-mapping>
<filter-name>EncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
你可以搞个servlet基类,里面预先做一下
httpResponse.setCharacterEncoding(encoding); // encoding为utf-8
httpResponse.setContentType("text/html; charset=utf-8");
然后你自己写的servlet都继承于这个基类就能搞定了啊,
在servlet里面加上就可以了,ajax传输是以utf-8的格式传输的
filter是请求到达前做一次处理,请求完成后再做一次处理,
而# httpResponse.setCharacterEncoding(encoding); // encoding为utf-8