Changing ParameterAware to HttpParametersAware

2019-07-27 22:54发布

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.

  1. setParameters(HttpParameters parameters) (struts 2.5.12)
  2. setParameters(Map<String,String[]> parameters) (struts 2.3.1)

How to do this?

1条回答
【Aperson】
2楼-- · 2019-07-27 23:21

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.

查看更多
登录 后发表回答