servlet 编码转换方法

public static String ISOtoGB2312(String input) throws Exception
    {
    String temp="";
    byte[] bytes = input.getBytes("ISO8859-1");
    temp=new String(bytes,"gb2312");
    return temp;
    }


    public static String GB2312toISO(String input) throws Exception
    {
    String temp="";
    try{
       byte[] bytes = input.getBytes("gb2312");
       temp=new String(bytes,"ISO8859-1");
    }catch(Exception ex){
       ex.printStackTrace();
    }
    return temp;
    }

前一个servlet用

response.sendRedirect("/Web/DoCN?type=type&name=" + GB2312toISO(name));

传到servlet(DoCN)后用

CharChange.ISOtoGB2312(request.getParameter("name"));

这样也就ok了。

你可能感兴趣的:(Web,servlet)