`

数据库中用户名是中文

 
阅读更多

数据库中文名+乱码:数据库中用户名是中文名

1,重新转码,new String(u.getBytes("iso-8859-1"),"GB2312")

   String u = request.getParameters("userName");

    u = new String(u.getBytes("iso-8859-1"),"GB2312");

2,使用过滤器来解决【后面详细讲解】

3,通过配置server.xml文件【不太稳定】

package com.dtg.model;
/**
 * 解决中文乱码问题,将iso-8859-1 转换成gb2312或utf-8
 * @author Administrator
 *
 */

public class TransNewString {
	public static String getNewString(String input){
		String result = null;
		try {
			result = new String(input.getBytes("iso-8859-1"),"gb2312");
		} catch (Exception e) {
			e.printStackTrace();
			// TODO: handle exception
		}
		return result;
	}
}

 

(3)server.xml 中

<Connector port="8080" protocol="HTTP/1.1" 
               connectionTimeout="20000" 
               redirectPort="8443" URIEncoding="gb2312" />

 

(4)若request接受出现乱码
String name =  new String (request.getParameter("userName").getBytes("iso-8859-1"),"gb2312")  
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics