我的一个过滤器类,代码:
public class SetCharacterEncodingFilter implements Filter {    
    protected String encoding = null;
    protected FilterConfig filterConfig = null;
    protected boolean ignore = true;    public void destroy() {        this.encoding = null;
        this.filterConfig = null;    }    public void doFilter(ServletRequest request, ServletResponse response,
                         FilterChain chain)
    throws IOException, ServletException {        // Conditionally select and set the character encoding to be used
        if (ignore || (request.getCharacterEncoding() == null)) {
            String encoding = selectEncoding(request);
            if (encoding != null)
                request.setCharacterEncoding(encoding);
        }    // Pass control on to the next filter
        chain.doFilter(request, response);    }    public void init(FilterConfig filterConfig) throws ServletException {        this.filterConfig = filterConfig;
        this.encoding = filterConfig.getInitParameter("encoding");
        String value = filterConfig.getInitParameter("ignore");
        if (value == null)
            this.ignore = true;
        else if (value.equalsIgnoreCase("true"))
            this.ignore = true;
        else if (value.equalsIgnoreCase("yes"))
            this.ignore = true;
        else
            this.ignore = false;    }    protected String selectEncoding(ServletRequest request) {        return (this.encoding);    }
}在web.xml中加入了如下代码
 <filter>
    <filter-name>Set Character Encoding</filter-name>
    <filter-class>com.gchj.struts.filter.SetCharacterEncodingFilter</filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
      <param-name>ignore</param-name>
      <param-value>true</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>Set Character Encoding</filter-name>
  <url-pattern>/*</url-pattern>
  </filter-mapping>
即字符编码过滤为UTF-8的格式,我在JSP页面把字符也设置为UTF-8的格式,然后把ApplicationResources.properties里的内容
# Resources for parameter 'com.gchj.struts.ApplicationResources'
guestbook=基于struts技术的留言板程序
image.struts=基于struts技术
guestbook.title=基于struts技术的留言板程序
prompt.id=用户名
prompt.password=密码
button.login=登陆
button.reset=重置
insert=添加留言
update=更新留言
delete=删除留言
searchID=按ID搜索
search=模糊查询
list=查看留言
mainMenu=返回主页
login=您还未登录,无权访问该页,请先登录
prompt.title=主题
prompt.author=作者
prompt.content=内容
button.insert=添加
button.update=更新
button.search=查询
button.delete=删除
button.searchID=搜索
ID=留言ID
input=请输入查询的关键字
success=操作成功
# Project guestbook
error.id.missing=用户名不能为空
error.password.missing=密码不能为空
error.title.missing=主题不能为空
error.author.missing=作者不能为空
error.content.missing=内容不能为空
error.ID.missing=ID不能为空用native2ascii编译器把字符也编译成UTF-8(zh_CN.properties)的形式,我的浏览器也是简体中文。
但在发布该web工程,然后测试时,还是出现了中文乱码,请问该如何解决?还有我从mysql数据库(我设置为了UTF8的格式)取
出的数据也是乱码,怎么弄?