关于网页请求URL中文乱码的Java服务端(Tomcat 7)解决方法 - 极简

/*接收请求*/
String username = request.getParameter("username");
String password = request.getParameter("password");
/*转码为正常UTF-8编码*/
username = new String(username.getBytes("iso8859-1"),"UTF-8");
password = new String(password.getBytes("iso8859-1"),"UTF-8");
/*从URL转码为正常格式*/
username = URLDecoder.decode(username, "UTF-8");
password = URLDecoder.decode(password, "UTF-8");
/*返回响应 (省略判断)*/
out.print("你好" + username + "  欢迎登陆");

猜你喜欢

转载自blog.csdn.net/activity_time/article/details/81132789