Request获取请求体数据的常用方法
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Map;
import java.util.Set;
@WebServlet("/RequestDemo2")
public class RequestDemo2 extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 单选框
// String username = request.getParameter("username");
// System.out.println(username);
// 复选框
// String[] parameterValues = request.getParameterValues("hobby");
// for (String and:parameterValues){
// System.out.println(and);
// }
// 获取所有信息的键值对
// Enumeration<String> parameterNames = request.getParameterNames();
// while (parameterNames.hasMoreElements()){
// String s = parameterNames.nextElement();
// String parameter = request.getParameter(s);
// System.out.println(s);
// System.out.println(parameter);
// System.out.println("=========");
// }
// 获取所有信息封装成map集合
// Map<String, String[]> parameterMap = request.getParameterMap();
// Set<String> strings = parameterMap.keySet();
// for (String s:strings){
// String[] strings1 = parameterMap.get(s);
// System.out.println(s);
// for (String s1:strings1){
// System.out.println(s1);
// }
// System.out.println("====");
// }
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request,response);
}
}