后台通过HttpServletRequest对象获取页面表单传递过来的参数的方式如下:
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//得到页面表单传递过来的键值对中的键所对应的值
String value = request.getParameter("name");
//页面表单中传递过来的键所对应的值可能有多个,通过该方法能够获得相应键的多个值
String[] values = request.getParameterValues("name");
for(String str:values){
System.out.println(str);
}
//以Map集合存储页面表单传递过来的所有参数的键值对
Map<String,String[]> map = request.getParameterMap();
Set<String> keySet = map.keySet();
Iterator<String> it = keySet.iterator();
while(it.hasNext()){
String key = it.next();
System.out.println(map.get(key));
}
//得到页面表单传递过来的所有参数的键值对中的键
Enumeration<String> key = request.getParameterNames();
while(key.hasMoreElements()){
System.out.println(key.nextElement());
}
//得到request的字符输入流
BufferedReader reader = request.getReader();
//得到request的字节输入流
ServletInputStream inStream = request.getInputStream();
}