前情提要:
使用过滤器对getParameterMap方法得到的参数进行处理,将其中符合条件的一些值替换为给定值,然后把修改后的值放入map中并将其返回
异常:
java.lang.IllegalStateException: No modifications are allowed to a locked ParameterMap
ParameterMap是被锁定的,不允许修改
查API:
Map<String,String[]> getParameterMap()
Returns a java.util.Map of the parameters of this request.
Request parameters are extra information sent with the request. For HTTP servlets, parameters are contained in the query string or posted form data.
Returns:
an immutable java.util.Map containing parameter names as keys and parameter values as map values. The keys in the parameter map are of type String. The values in the parameter map are of type String array.
发现返回的是一个不可变的Map,因此需要对返回的Map进行处理
解决:
将 Map<String, String[]> parameterMap = Map<String, String[]>) method.invoke(request, args);替换为
Map<String, String[]> parameterMap = new HashMap<>((Map<String, String[]>) method.invoke(request, args));