java_newbie
java_newbie

Reputation: 871

Struts2 get parameter from Request GET type

in my Struts2 app I have such GET requests for internal logic: http:/ /local_ip:8080/struts/admin/editUser?login=SomeLogin

to extract parameter value from request I wrote a code in my execute() method:

Map<String, Object> params = ActionContext.getContext().getParameters();
String[] logins = (String[]) params.get("login");
String login = logins[0]; //here we have correct value = SomeLogin

Yeah, it works but seems to be too large for such small thing. Is there a better way? thx for any hint.

Upvotes: 2

Views: 4121

Answers (1)

Dave Newton
Dave Newton

Reputation: 160181

You might want to read over some of the Struts 2 documentation.

public class MyAction extends ActionSupport {
    private String login;
    public void setLogin(String login) { this.login = login; }
}

Seems easier, yes? Some time with the documentation now will save you a lot of time in the future.

Upvotes: 2

Related Questions