有人知道在Struts2拦截器中是否可以更改/删除请求参数值吗?
request参数Map是的实例,UnmodifiableMap因此看起来好像无法在拦截器中进行操作。
Map
UnmodifiableMap
更新:
我正在使用Liferay,所以uParamsMap会UnmodifiableMap
uParamsMap
public String intercept(ActionInvocation invocation) throws Exception { final ActionContext context = invocation.getInvocationContext(); PortletRequest request = (PortletRequest) context.get(REQUEST); Map<String, String[]> uParamsMap = request.getParameterMap(); return invocation.invoke(); }
也许您可以这样尝试。
public String intercept(ActionInvocation invocation) throws Exception { final ActionContext context = invocation.getInvocationContext(); Map<String,Object> parameters = (Map<String,Object>)context.get(ActionContext.PARAMETERS); Map<String, Object> parametersCopy = new HashMap<String, Object>(); parametersCopy.putAll(parameters); parametersCopy.put("myParam", "changedValue"); context.put(ActionContext.PARAMETERS, parametersCopy); return invocation.invoke(); }