How to access url parameters in struts2

I am working on a struts2 project. I created a url in my project and passed the parameters using tags. My question is: how can I read a parameter in actions? also if I do the same, I can see the parameters as a query string. I ask because I cannot, and I saw this in one of the lessons.

+3
source share
2 answers

As a rule, you will interact with parameters in your actions using the fields in your actions set by the setters. Assume the following URLs for my example Struts2 action:

URL

http: // localhost / myAction? firstName = SonOfTheEARTh

Action code

public class MyAction extends ActionSupport {
    private String firstName;

    public String execute() throws Exception {
        // do something here
        return SUCCESS;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(final String firstName) {
        this.firstName = firstName;
    }
}

Jsp

Struts: <s:property value="firstName"/>

JSP EL/JSTL: ${action.firstName}

+5

EDITED: . , "oldName".

0

Source: https://habr.com/ru/post/1781015/


All Articles