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获取请求参数通用方式的更多相关文章

  1. 入门servlet:request获取请求参数通用方式

    一.获取请求参数通用方式 1. String getParameter(String name):根据参数名称获取参数值 例:username=flypig&password=2343 2. ...

  2. request 获取请求参数

    /** * 根据request获取请求的用户参数 * @return * @return */ protected <T> T getParamConvertEntity(Class cl ...

  3. request获取请求参数

    /** * 方式1 */ Enumeration<?> enu=request.getParameterNames(); while(enu.hasMoreElements()){ Str ...

  4. request对象常用API 获取请求参数的值 request应用 MVC设计模式

    1 request对象常用API   1)表示web浏览器向web服务端的请求   2)url表示访问web应用的完整路径:http://localhost:8080/day06/Demo1     ...

  5. struts2获取请求参数的三种方式及传递给JSP参数的方式

    接上一篇文章 package test; import com.opensymphony.xwork2.ActionSupport; import javax.servlet.http.*; impo ...

  6. 学习SpringMVC——如何获取请求参数

    @RequestParam,你一定见过:@PathVariable,你肯定也知道:@QueryParam,你怎么会不晓得?!还有你熟悉的他(@CookieValue)!她(@ModelAndView) ...

  7. springMvc源码学习之:spirngMVC获取请求参数的方法2

    @RequestParam,你一定见过:@PathVariable,你肯定也知道:@QueryParam,你怎么会不晓得?!还有你熟悉的他 (@CookieValue)!她(@ModelAndView ...

  8. 学习SpirngMVC之如何获取请求参数

    学习SpringMVC——如何获取请求参数   @RequestParam,你一定见过:@PathVariable,你肯定也知道:@QueryParam,你怎么会不晓得?!还有你熟悉的他(@Cooki ...

  9. springMVC(spring)+WebSocket案例(获取请求参数)

    开发环境(最低版本):spring 4.0+java7+tomcat7.0.47+sockjs 前端页面要引入: <script src="http://cdn.jsdelivr.ne ...

随机推荐

  1. 【Docker】Asp.net core在docker容器中的端口问题

    还记得[One by one系列]一步步学习docker(三)--实战部署dotnetcore中遇到的问题么?容器内部启动始终是80端口,并不由命令左右. docker run --name cont ...

  2. WebJar的打包和使用  

    前言 WebJar官网:https://www.webjars.org/,对于任何与Servlet 3兼容的容器,WEB-INF/lib目录中的webjar都会自动作为静态资源提供.这是因为WEB-I ...

  3. C# 判断未将对象引用设置到对象的实例,出错的代码到底在第几行

    DataTable dt = null; try { var x = dt.Rows.Count; } catch(NullReferenceException nullexception) { Me ...

  4. request模块做post请求时,body为json格式,并且带有中文,如何请求

    后台接口只能解析json,并且一定要是中文才能解析出来,如果是unicode编码的中文则会报错 看requests的源码.以下为解决方法: #将requests库中的models.py文件中的第461 ...

  5. [hdu7011]被EI加0了

    注意到仅关心于权值大小,预处理出$F_{i}(n)$​​​​表示$a_{1},a_{2},...,a_{n}$​​​​中恰填$i$​​​​​​种不同的数的方案数,那么显然答案即为$\sum_{i=1} ...

  6. [bzoj5343]混合果汁

    二分枚举答案,问题转化为计算至少取到一定体积,价格最少是多少,显然是贪心取最小,用线段树维护,然后因为要判断答案,所以可持久化一下即可. 1 #include<bits/stdc++.h> ...

  7. springboot访问静态资源404

    <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring- ...

  8. springboot和springcloud版本上的选择

    现在的springboot项目和cloud版本都是更新很快,但我们开发不是版本越新越好,我们要把版本对应起来,那么我们怎么去关联呢? springboot和springcloud不是越新越好,clou ...

  9. LoadRunner 2020 社区版本负载机(Load generator)Linux 安装教程

    1.HP官方注册 下载 LoadRunner_2020_Edition_Standalone_Applications_Micro_Focus_LoadRunner_2020_Community_Ed ...

  10. java 适配器模式实现代码

    目录 1.适配器模式 1.1.类适配器 1.2.对象适配器 2.适配器模式实例 1.适配器模式 适配器模式可以分为类适配器和对象适配器. 1.1.类适配器 //目标接口 interface Targe ...