多个参数如何接收

当我们表单页面有多个值向后台传递时,我们可用从request对象里面获取所有参数

代码:

		//从request里获取所有参数名称
		Enumeration names = request.getParameterNames();
		//创建一个hashMap来存放数据
		HashMap hm = new HashMap();
		//从names里面遍历数据放入hm
		while(names.hasMoreElements()){
			String key = names.nextElement();
			String value = request.getParameter(key);
			hm.put(key, value);
		}
		System.out.println("我从对象里获取的数据是:"+hm);

封装到Map后,可用根据你自身的需求来操作啦!

你可能感兴趣的:(实用代码)