把地址栏中参数变乱码的问题

来源:百度知道 编辑:UC知道 时间:2024/05/24 15:58:38
把参数变为乱码
<script language="javascript">
var str="参数乱码";
window.location.href="userhome.jsp?uid="+encodeURI(str);
</script>

在userhome.jsp获得uid值,用下面方法解码,
uid=URLDecoder.decode(request.getParameter("uid"));
但得到的依然是乱码,怎么办

//把以iso编码转换为字符串内码
public static String ISOToInnerCode(String str) {
if (str == null)
return null;

try {
str = (new String(str.getBytes("ISO-8859-1"), "UTF-8")).trim();
} catch (Exception ex) {
}

return str;
}

---------------------------------------------

你从页面传到java中时,可能2个地方用的编码格式不一样。需要转换。