java学习

java学习

 

中文字符转码

1.    String s = “中文”;
S = new String(s.getBytes(“ISO8859-1”),”utf-9”);
2.    使用过滤器:
public class CharsetFilter implements Filter{

    private String encoding = "UTF-8";
    
    public void destroy() {
        
    }

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

    public void init(FilterConfig filterConfig) throws ServletException {
        String encoding = filterConfig.getInitParameter("encoding");
        if(encoding != null) {
            this.encoding = encoding;
        }
    }

}
3.request.setCharacterEncoding(“utf-8”);

posted on 2012-05-04 21:55 杨军威 阅读(1900) 评论(0)  编辑  收藏


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


网站导航:
 

导航

统计

常用链接

留言簿

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜