复选框Value为中文,提交时出现乱码
初学jsp,乱码问题却一直困扰着我。字符串我们可以这样:
String tName=new String(request.getParameter( "tName ").getBytes( "ISO-8859-1 "));
但是数组却不知如何处理好。下面是我的代码:
String dot= ", ";//分隔符
String tLang= " ";
String tLangs[]=request.getParameterValues( "tLang ");
if(tLangs!=null)
{
for(int i=0;i <tLangs.length;i++)
{ tLang+=tLangs[i]+dot;}
tLang=tLang.substring(0,tLang.length()-1); //去掉最后一个“,”
}
out.print( "语言: "+tLang+ " <br> ");
输出变量tLang为乱码。一直很郁闷,请各位高手帮忙看看,感激不尽!
------解决方案--------------------String tLangs[]=request.getParameterValues( "tLang ");
for(int n=0;n <tLangs.length;n++){
tLangs[n] = new String(tLangs[n].getBytes( "ISO-8859-1 "));
}