错误: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对象复制到另一个域空间里。
参考: