http://localhost:8080/webDemo1/TestServlet?aaa=2&bbb=1,通过请求,我们可以获得相应的请求参数。注意,这个set集合的key是sting类型的,但是value是String类型的数组。
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Map<String, String[]> map = request.getParameterMap(); Set<Entry<String, String[]>> set = map.entrySet(); Iterator<Entry<String, String[]>> it = set.iterator(); while(it.hasNext()){ Entry<String, String[]> en = it.next(); System.out.println("key: "+en.getKey()); for(int a=0;a<en.getValue().length;a++){ System.out.println(en.getValue()[a]); } } }