1 get情况
response.setContentType("text/html; charset=utf-8"); //通知浏览器以utf-8编码格式打开内容
//把输入的默认iso-8859-1格式转换为utf-8
String first_name = request.getParameter("first_name");
first_name = new String(first_name.getBytes("iso-8859-1"),"utf-8");
注:如果需要把中文字符串作为cookie内容使用,需要再对上述的处理结果做转换
String first_name_ckstr = java.net.URLEncoder.encode(first_name, "utf-8");
读取cookie内容时,需要对应使用解码函数
first_name = java.net.URLDecoder.decode(first_name_ckstr, "utf-8");
2 post情况
// 设置输入post输入编码类型
request.setCharacterEncoding("utf-8");
//通知浏览器以utf-8编码格式打开内容
response.setContentType("text/html; charset=utf-8");