String user=request.getParameter("user");//返回唯一值
String []hobby=request.getParameterValues("hobby");//返回多个值, 获取的是html中的nameString 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("<html><body>");
out.print("用户名:"+user+"<br>");
out.print("兴趣爱好:");
if( hobby!=null)//防止出现 java.lang.NullPointerException
for(int i=0;i<hobby.length;i++)
{
hobby[i]=new String(hobby[i].getBytes("iso8859-1"),"UTF-8");//防乱码,先转换再输出
out.print(hobby[i]+" ");
}
out.print("<br>");
out.print("政治面貌:"+zhengzhi+"<br>");// 输出的是value