package com.hdh.requesd; import java.io.IOException; import java.util.Enumeration; import java.util.Map; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import java
import java.io.IOException;
import java.util.Enumeration;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ContentServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// 1.获取单个表单中的value值
String usernam=request.getParameter("usernam");
String password =request.getParameter("password");
System.out.println("usernam.value:" + usernam);
System.out.println("password.value:" + password);
// 2.获取多个表单的value值
String[] parameterValues=request.getParameterValues("hobby");
System.out.print("hobby.values:");
for (String string : parameterValues) {
System.err.print(string + " ");
}
System.out.println("---------------------");
// 3.获得所有参数的name
Enumeration
parameterNames= request.getParameterNames();
for (String string2 : parameterValues) {
System.out.println(parameterNames.nextElement());
}
System.out.println("---------------------");
// 4.将获得的所有参数封装到一个Map
中
Map
parameterMap= request.getParameterMap();
for (Map.Entry
entry : parameterMap.entrySet()) {
System.out.println(entry.getKey());
for (String string : entry.getValue()) {
System.out.println(string);
}
System.out.println("----------------");
}
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}