ServletRequest 【专题】

 

获取所有header

复制代码
private static Map<String, String> getHeaders(HttpServletRequest request) {
        Map<String, String> headerMap = new HashMap<>();
        Enumeration<String> enumeration = request.getHeaderNames();
        while (enumeration.hasMoreElements()) {
            String name    = enumeration.nextElement();
            String value = request.getHeader(name);
            headerMap.put(name, value);
        }
        return headerMap;
    }
复制代码

 

获取所有QueryString参数

复制代码
private static Map<String, String> getParameters(HttpServletRequest request) {
        Map<String, String> parameterMap = new HashMap<>();
        Enumeration<String> enumeration = request.getParameterNames();
        while (enumeration.hasMoreElements()) {
            String name    = enumeration.nextElement();
            String value = request.getParameter(name);
            parameterMap.put(name, value);
        }
        return parameterMap;
    }
复制代码

 

获取所有Cookie信息

复制代码
    /**
     * 获取所有Cookie信息
     *
     * @param cookies
     * @return
     */
    private String collectAllCoolies(Cookie[] cookies) {
        if (cookies != null) {
            StringBuilder content = new StringBuilder();
            Arrays.stream(cookies).filter(Objects::nonNull).forEach(cookie -> {
                content.append(" [ ")
                        .append(cookie.getName()).append(" : ").append(cookie.getValue())
                        .append(" ] ");
            });
            return content.toString();
        }
        return "";
    }
复制代码

 

 


基于cookie使用过滤器实现客户每次访问自登陆一次 
https://www.cnblogs.com/softidea/p/6946776.html

 
posted @   沧海一滴  阅读(20)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下
历史上的今天:
2019-12-05 Spring Boot 2.2.1 正式发布,需特别注意这个注解的使用!
2018-12-05 Spring4新特性——集成Bean Validation 1.1(JSR-349)到SpringMVC
2016-12-05 Spring MVC的异步模式DefferedResult
2016-12-05 mysql解决datetime与timestamp精确到毫秒的问题
2016-12-05 更改MySQL数据库的编码为utf8mb4
2016-12-05 MySQL中的表中增加删除字段
2014-12-05 No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
点击右上角即可分享
微信分享提示