问题
I'm upgrading my project from struts 2.3.1 to 2.5.12
Since ParametersAware
is deprecated in 2.5.12, I want to change ParametersAware
to HttpParametersAware
.
But setParameter()
method is entirely different in both.
setParameters(HttpParameters parameters)
(struts 2.5.12)setParameters(Map<String,String[]> parameters)
(struts 2.3.1)
How to do this?
回答1:
Change Map<String,String[]>
to HttpParameters. The later class implements a Map<String,Parameter>
, so you can use
this to get/put parameters to the map.
The most interesting is a Parameter interface that has implementations Parameter.Empty, Parameter.File, Parameter.Request. The last one is used to retrieve request parameters.
This answer How could I get a parameter in JSP will throw a light on a typical usage of request parameters if you want to manipulate parameters manually.
Another approach (which is not recommended) is to get request parameters from the request itself. See Interceptors use in login in Struts 2.0.
来源:https://stackoverflow.com/questions/45296712/changing-parameteraware-to-httpparametersaware