jsp传入servlet出现乱码

post方法

request.setCharacterEncoding("UTF-8");//传值编码
response.setContentType("text/html;charset=UTF-8");//设置传输编码

get方法

1、  String username=request.getParameter("username");
        String username1=new String(username.getBytes("ISO-8859-1"),"utf-8");

2、在tomcat服务器中修改server.xml:URIEncoding="utf-8",因为在Tomcat5.0中和以后,默认情况下使用ISO-8859-1对URL提交的数据和表单中GET方式提交的数据进行重新编码。

3、

  浏览器中两次URL编码。

  服务器中自己再做一次URL解码。

猜你喜欢

转载自www.cnblogs.com/XYJ-MK/p/12968470.html