在 Struts2 拦截器中更改请求参数值 [英] Changing request parameter value in Struts2 interceptor
本文介绍了在 Struts2 拦截器中更改请求参数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有谁知道是否可以在 Struts2 拦截器中更改/删除请求参数值?
Does anybody know if it is possible to change/remove request parameter values in a Struts2 interceptor?
请求参数Map
是UnmodifiableMap
的一个实例,所以它看起来不能在拦截器中操作.
The request parameter Map
is an instance of UnmodifiableMap
so it doesn't look like it can be manipulated with in the interceptor.
更新:
我正在使用 Liferay,所以 uParamsMap
将是一个 UnmodifiableMap
I'm using Liferay so uParamsMap
will be an UnmodifiableMap
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();
}
这篇关于在 Struts2 拦截器中更改请求参数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文