首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

自学Servlet_七_resquest(获取客户机带过来的数据)

2013-12-11 
自学Servlet_7_resquest(获取客户机带过来的数据)获取客户机带过来的数据三种情况://1.//http://localhost

自学Servlet_7_resquest(获取客户机带过来的数据)
获取客户机带过来的数据三种情况:

//1.//http://localhost:8080/day06/servlet/RequestDemo3?name=xxxString value = request.getParameter("name");System.out.println(value);System.out.println("-----");//2.//http://localhost:8080/day06/servlet/RequestDemo3?name=xxx&password=123Enumeration e = request.getParameterNames();while(e.hasMoreElements()){String name = (String) e.nextElement();value = request.getParameter(name);System.out.println(name + "=" + value );}System.out.println("----");//3.//http://localhost:8080/day06/servlet/RequestDemo3?name=xxx&name=yyyyString values[] = request.getParameterValues("name");/*if(values!=null){for(String value1 : values){System.out.println(value1);}}*/for(int i=0;values!=null && i<values.length;i++){   //这样的代码可以预防null指针的问题System.out.println(values[i]);}System.out.println("--map--");//4.// http://localhost:8080/day06/servlet/RequestDemo3?a=1&a=2&b=1Map<String,String[]> map = request.getParameterMap();  //a=1&a=2&b=1for(Map.Entry<String, String[]> entry : map.entrySet()){String name  = entry.getKey();values = entry.getValue();   //[]for(int i=0;values!=null && i<values.length;i++){value = values[i];System.out.println(name + "=" + value);}}

热点排行