首页 > 其他 > 详细

request获取请求参数通用方式

时间:2019-08-31 19:34:51      阅读:92      评论:0      收藏:0      [点我收藏+]

package com.hopetesting.web.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.Iterator;
import java.util.Map;
import java.util.Set;

/**
* @author newcityman
* @date 2019/8/31 - 18:20
*/
@WebServlet("/requestDemo06")
public class RequestDemo06 extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String username = request.getParameter("username");
String password = request.getParameter("password");
System.out.println("========");
System.out.println(username + ":::" + password);
String[] hobbies = request.getParameterValues("hobby");
for (String hobby : hobbies) {
System.out.println(hobby);
}
System.out.println("===================================");
Enumeration<String> parameterNames = request.getParameterNames();
while (parameterNames.hasMoreElements()) {
String s = parameterNames.nextElement();
System.out.println(s);
String parameter = request.getParameter(s);
System.out.println(parameter);
}
System.out.println("++++++++++++++++++++++++++++++++++++");

Map<String, String[]> parameterMap = request.getParameterMap();
Set<String> strings = parameterMap.keySet();
for (String name : strings) {
String[] values = request.getParameterValues(name);
System.out.println(name);
for (String value : values) {
System.out.println(value);
}
System.out.println("+++++++++++++++++++++++++++++++++++++++");
}

}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request, response);
}
}
 

request获取请求参数通用方式

原文:https://www.cnblogs.com/newcityboy/p/11440090.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!