No modifications are allowed to a locked ParameterM&ParameterMap cannot be cast to java.util.HashMap
8402 ワード
エージェント・モードを使用してgetParameterMapの戻り値を変更すると、No modifications are allowed to a locked ParameterMapとエラーが発生しました.
以下を調べる
request.getParameterMap()戻り値mapは変更できないmapですか?https://blog.csdn.net/Luminescende/article/details/81140554
テストは以下の通りである.invoke(req, args); Map map = new HashMap(map1);
完全なコードは次のとおりです.
以下を調べる
request.getParameterMap()戻り値mapは変更できないmapですか?https://blog.csdn.net/Luminescende/article/details/81140554
テストは以下の通りである.invoke(req, args); Map map = new HashMap(map1);
完全なコードは次のとおりです.
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
ServletRequest proxy_req = (ServletRequest) Proxy.newProxyInstance(req.getClass().getClassLoader(), req.getClass().getInterfaces(), new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
// getParameter
if (method.getName().equals("getParameterMap")) {
//
// Map map =(Map) method.invoke(req, args);
//
Map<String, String[]> map = new HashMap<String,String[]>((Map<String,String[]>) method.invoke(req, args));
for (String key : map.keySet()) {
String[] values = map.get(key);
//list
for (String str : list) {
if (values[0].contains(str)) {
values[0] = values[0].replaceAll(str, "***");
}
}
map.put(key,values);
}
return map;
}
return method.invoke(req,args);
}
});
chain.doFilter(proxy_req, resp);
}
```