HttpServletRequest對象中常用的獲取請求參數的方法:
1、getParameter("java.lang.String.parameterName"):獲取表單參數值,參數名區分大小寫,不管是get請求還是post請求都可以使用該方法,如果沒有對應的參數,該方法返回null。
2、getParameterValues("java.lang.String.parameterName"):獲取同一個參數名的多個參數值,返回字符串數組對象。
3、getParameterNames():該方法無參數,以Enumeration(枚舉)的方式返回請求中所有的表單參數名列表。
關於枚舉遍歷參數示例:
// 得到枚舉對象 Enumeration emum = request.getParameterNames(); // 循環遍歷 while(enum.hasMoreElements()){ // 表單參數名 String paramName = (String) enum.nextElement(); // 表單參數值,可能存在一個參數名對應多個參數值的情況 String [ ] paramValues = request.getParameterValues(paramName); // 遍歷參數名對應的參數值數組 for(int i = 0; i < paramValues.length; i++){ // 參數值 String paramValue = paramValues[ i ]; } }