How to access url parameters in struts2

心不动则不痛 提交于 2019-12-03 08:48:34

Typically, you will interact with parameters in your actions by using fields on your actions, exposed by setters. Assume the following URL maps to 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

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

Using JSP EL/JSTL: ${action.firstName}

EDITED answer: It's based on naming conventions of your parameter. Take a look at this link and follow how they set "oldName" parameter.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!