import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class GetRequestParameters extends HttpServlet{
private static final long serialVersionUID = 1L;
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
//如果参数名相同默认取第一个
String userName=req.getParameter("userName");
String passwd=req.getParameter("password");
//如果参数名相同全部取出
String []hobbies=req.getParameterValues("hobby");
//这种方式获取全部参数,封装在map中需要进行进一步遍历
Map params = req.getParameterMap();
for(String key:params.keySet()){
for(String value:params.get(key)){
System.out.println(key+" : "+value);
}
}
}
}