随笔-208  评论-469  文章-30  trackbacks-0

在web.xml文件中添加:

<filter>
  <filter-name>Set Character Encoding</filter-name>
  <filter-class>
   com.SetCharacterEncodingFilter
  </filter-class>
 </filter>
 <filter-mapping>
  <filter-name>Set Character Encoding</filter-name>
  <url-pattern>*.do</url-pattern>
 </filter-mapping>

 SetCharacterEncodingFilter  类代码如下:

package com.db;

/**
 * @author cool
 *
 */

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

public class SetCharacterEncodingFilter implements Filter {

 public void init(FilterConfig config) throws ServletException {

 }

 public void destroy() {

 }

 public void doFilter(ServletRequest request, ServletResponse response,
   FilterChain chain) throws IOException, ServletException {
  request.setCharacterEncoding("GB2312");
  chain.doFilter(request, response);
 }
}

前提是你必须要设置好eclipse和myeclipse的字符集,将所有字符集都设为UTF-8,见我的文章,这样就不用在任何地方

犯愁乱码了。

posted on 2007-02-08 23:24 EricWong 阅读(389) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: