-
java如何得到GET和POST请求URL和参数列表
- 在servlet中GET请求可以通过HttpServletRequest的getRequestURL方法和getQueryString()得到完整的请求路径和请求所有参数列表,POST的需要getParameterMap()方法遍历得到,不论GET或POST都可以通过getRequestURL+getParameterMap()来得到请求完整路径
- package com.zuidaima
- import java.io.IOException;
- import java.io.PrintWriter;
- 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 GetParams extends HttpServlet {
- private static final long serialVersionUID = 1L;
-
- public GetParams() {
- super();
- }
-
- protected void doGet(HttpServletRequest request,
- HttpServletResponse response) throws ServletException, IOException {
- PrintWriter writer = response.getWriter();
- writer.println("GET " + request.getRequestURL() + " "
- + request.getQueryString());
-
- Map<String, String[]> params = request.getParameterMap();
- String queryString = "";
- for (String key : params.keySet()) {
- String[] values = params.get(key);
- for (int i = 0; i < values.length; i++) {
- String value = values[i];
- queryString += key + "=" + value + "&";
- }
- }
-
- queryString = queryString.substring(0, queryString.length() - 1);
- writer.println("GET " + request.getRequestURL() + " " + queryString);
- }
-
- protected void doPost(HttpServletRequest request,
- HttpServletResponse response) throws ServletException, IOException {
- PrintWriter writer = response.getWriter();
- Map<String, String[]> params = request.getParameterMap();
- String queryString = "";
- for (String key : params.keySet()) {
- String[] values = params.get(key);
- for (int i = 0; i < values.length; i++) {
- String value = values[i];
- queryString += key + "=" + value + "&";
- }
- }
-
- queryString = queryString.substring(0, queryString.length() - 1);
- writer.println("POST " + request.getRequestURL() + " " + queryString);
- }
- }
-
相关阅读:
Postman+Newman生成接口测试报告
Spring Boot系列 – 2. Spring Boot提供的特性
Spring Boot系列 – 5. 不同的环境使用不同的配置
Spring Boot系列 – 4. 读取配置文件(application.yml)中的属性值
MySQL高可用之MHA安装
恢复误删除表黑科技之relay log大法(续)
恢复误删除表黑科技之relay log大法
关于mysqldump备份非事务表的注意事项
利用binlog server及Xtrabackup备份集来恢复误删表(drop)
基于Xtrabackup备份集来恢复某个误删除的表(drop)
-
原文地址:https://www.cnblogs.com/suifengbingzhu/p/4442923.html
Copyright © 2020-2023
润新知