处理request中文乱码的一个比较low,单管用的方法

来源:互联网 发布:小牛数据恢复 编辑:程序博客网 时间:2024/05/20 17:09
    String username = request.getParameter("username");
    byte[] bytes = username.getBytes("iso-8859-1");
    String result = new String(bytes, "gb2312");

    out.print(result);





如我们所见,先从request中获得参数,接着把字符串按照iso-8859-1编码打散成byte数组,然后用gb2312编码组合成新字符串,最后打印出来就是正常的中文了。

(其中的码制根据具体情况进行变换)



0 0