日期:2014-05-16  浏览次数:20471 次

java/jsp中文转码

?

所有页面编码皆为UTF-8

中文流转过程:action1->js->jsp->action2

?

action1:java.net.URLEncoder.encode(username, "UTF-8")

js:不做任何处理,将该变量直接传给jsp

jsp:

String j_username = request.getParameter("userName");?
?Properties props = System.getProperties(); //获得系统属性集???
?String osName = props.getProperty("os.name"); //操作系统名称???
?
?if(osName.toLowerCase().indexOf("windows") > -1){
??
?} else {
??j_username = new String(j_username.getBytes("ISO8859_1"),"UTF-8");
??j_username = java.net.URLEncoder.encode(j_username, "UTF-8");
?}

?

action2:String userName= request.getParameter("userName");

?

?

?

?

?

?

?

?