页面都用UTF-8了,而且数据库链接池也做了编码控制,还是出现了乱码。不过刚开始用那个数据库,还没有用FILTER都没有乱码。于是我想到是否用个FILTER试试。
过程:
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


<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--> 1

2

3

4

5

6

7

8

9

10

11

12

注意在所有servlet 之前。
遗憾的测试发现还是有乱码。不过这个配置是正确的。所以最后数据库师父说,数据库问题。他说换个版本就行了。
不过想想今天做的事情吧,学会了连接池配置,filter配置,还能熟练用一个开源的js TREE组件。
不错吧!