jsp提交数据乱码

  get提交方式提交数据乱码

 这样的数据提交到后台中文直接乱码提交最后网上查了下:

因为get方法是参数在URL中显示,因为tomcat的URL编码默认是:IOS-8859-1所以要么改tomcat

第1种方法(治本):tomcat-config-sever.xml 

加URIEncoding="utf-8"或者useBodyEncodingForURI="true"

 第2种方法(治标):要么要针对性的对乱码的参数进行单独转码

<%
String username = request.getParameter("username");
String name = new String(username.getBytes("ios-8859-1"),"utf-8");

String password = request.getParameter("password");
out.print("--用户名是:"+name+"--密码是:"+password);
%>

我是直接采用第一种直接改了下Tomcat中的server.xml中的配置提交数据后正常了。。。。。

转载:https://www.cnblogs.com/sincoolvip/p/5746678.html?utm_source=itdadao&utm_medium=referral

原文地址:https://www.cnblogs.com/wolf-shuai/p/14662915.html