页面都用UTF-8了,而且数据库链接池也做了编码控制,还是出现了乱码。不过刚开始用那个数据库,还没有用FILTER都没有乱码。于是我想到是否用个FILTER试试。
然后将过滤器添加到web.xml
过程:
1
package org.cotel.Evote.Util;
2
3
import java.io.IOException;
4
import javax.servlet.*;
5
6
public class EncodingFilter implements Filter{
7
private String encoding;
8
public EncodingFilter(){
9
}
10
public void init(FilterConfig filterconfig)
11
throws ServletException{
12
encoding = filterconfig.getInitParameter("encoding");
13
}
14
15
public void doFilter(ServletRequest servletrequest, ServletResponse servletresponse, FilterChain filterchain)
16
throws IOException, ServletException{
17
if(encoding != null && servletrequest.getCharacterEncoding() == null)
18
servletrequest.setCharacterEncoding(encoding);
19
filterchain.doFilter(servletrequest, servletresponse);
20
}
21
public void destroy(){
22
}
23
}
24
25

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

然后将过滤器添加到web.xml