No modifications are allowed to a locked ParameterMap

简介: 错误:java.lang.IllegalStateException: No modifications are allowed to a locked ParameterMap at org.apache.catalina.util.ParameterMap.remove(ParameterMap.java:205) 1.Servlet中使用了这个方法:request.getParameterMap(),将它的返回值赋值给一个空的hashmap对象结果报错。
错误: java.lang.IllegalStateException: No modifications are allowed to a locked ParameterMap

at org.apache.catalina.util.ParameterMap.remove(ParameterMap.java:205)

1.Servlet中使用了这个方法:request.getParameterMap(),将它的返回值赋值给一个空的hashmap对象结果报错。参考:

it looks like you are trying to *modify* the > received form parameters Map, which under Tomcat's interpretation of > HTTP request handling is a no-no. (The Servlet Spec 3.0 does not > explicitly say so (Chapter 3), but strongly hints in that direction > (there are only "get" methods, no "set" ones).

貌似Servlet规范隐晦的告诉了我们这点。

The relevant info is in the Javadoc for ServletRequest#getParameterMap(). It states quite clearly that the parameter map is immutable.

这个方法的返回值是不可变的。

作者还说一些关键信息却只能在javadoc里找到真是令人抓狂啊~

2.解决方法是:new HashMap(request.getParameterMap())

因为直接用等好赋值只是地址引用,并未改变内存空间,因此无法对之前产生的那个被锁定的map对象进行操作,而使用new方法确实重新申请了内存地址,将该“不可变”的map对象复制到另一个域空间里。

参考:

1.http://goo.gl/pvweu

2.http://goo.gl/AEvPN

 

https://my.oschina.net/cwalet/blog/35431

 

不能被修改的原因:

org.apache.catalina.util.ParameterMap

 /**
     * Associate the specified value with the specified key in this map.  If
     * the map previously contained a mapping for this key, the old value is
     * replaced.
     *
     * @param key Key with which the specified value is to be associated
     * @param value Value to be associated with the specified key
     *
     * @return The previous value associated with the specified key, or
     *  <code>null</code> if there was no mapping for key
     *
     * @exception IllegalStateException if this map is currently locked
     */
    @Override
    public V put(K key, V value) {

        if (locked)
            throw new IllegalStateException
                (sm.getString("parameterMap.locked"));
        return (super.put(key, value));

    }

 

相关文章
|
缓存 运维 Java
nacos常见问题之点击下线提示报错如何解决
Nacos是阿里云开源的服务发现和配置管理平台,用于构建动态微服务应用架构;本汇总针对Nacos在实际应用中用户常遇到的问题进行了归纳和解答,旨在帮助开发者和运维人员高效解决使用Nacos时的各类疑难杂症。
521 2
|
JSON Java 应用服务中间件
HttpServletRequest核心方法以及获取请求参数
HttpServletRequest核心方法以及获取请求参数
2258 0
|
SQL 存储 负载均衡
MySQL实战 主从同步(原理+实战)
MySQL实战 主从同步(原理+实战)
MySQL实战 主从同步(原理+实战)
|
存储 机器学习/深度学习 人工智能
【DSW Gallery】DSW基础使用介绍
PAI-DSW是一款云端机器学习开发IDE,为您提供交互式编程环境,适用于不同水平的开发者。本文为您介绍PAI-DSW的功能特点以及界面的基础使用。
【DSW Gallery】DSW基础使用介绍
java生成word(使用Poi-tl)
java生成word(使用Poi-tl)
895 0
|
人工智能 自然语言处理 Java
Spring AI,Spring团队开发的新组件,Java工程师快来一起体验吧
文章介绍了Spring AI,这是Spring团队开发的新组件,旨在为Java开发者提供易于集成的人工智能API,包括机器学习、自然语言处理和图像识别等功能,并通过实际代码示例展示了如何快速集成和使用这些AI技术。
Spring AI,Spring团队开发的新组件,Java工程师快来一起体验吧
|
Web App开发 JSON JavaScript
WebGL简易教程(十五):加载gltf模型
WebGL简易教程(十五):加载gltf模型
398 1
|
监控 安全 Java
使用JMX监控Tomcat
【7月更文挑战第18天】
243 3
【UI】elementui select点击获取label 和 value
【UI】elementui select点击获取label 和 value
478 1
|
消息中间件 测试技术 领域建模
DDD - 一文读懂DDD领域驱动设计
DDD - 一文读懂DDD领域驱动设计
39645 5

热门文章

最新文章