【web】java后台获取checkbox、radio的值并输出

                String user=request.getParameter("user");//返回唯一值

String []hobby=request.getParameterValues("hobby");//返回多个值, 获取的是html中的name

String zhengzhi=request.getParameter("zhengzhi");

                //显示乱码处理

//一般情况下,服务器默认的编码是“iso8859-1”,所以我们需要数据还原,然后再转换成UTF-8的形式  (见收藏)
zhengzhi=new String(zhengzhi.getBytes("iso8859-1"),"UTF-8");

response.setContentType("text/html;charset=utf-8");//貌似不起作用
PrintWriter out=response.getWriter();

out.print("");
out.print("用户名:"+user+"
");

out.print("兴趣爱好:");
if( hobby!=null)//防止出现 java.lang.NullPointerException
for(int i=0;i {
hobby[i]=new String(hobby[i].getBytes("iso8859-1"),"UTF-8");//防乱码,先转换再输出
out.print(hobby[i]+" ");
}

out.print("
");

out.print("政治面貌:"+zhengzhi+"
");// 输出的是value

你可能感兴趣的:(web)