3

我正在做一个 struts2 项目。我在我的项目中创建了 url 并使用标签传递了参数。我的问题是如何读取动作中的参数?如果也这样做,我将能够将参数视为查询字符串。我问是因为我做不到,我在其中一个教程中看到了。

4

2 回答 2

5

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}

于 2010-12-18T23:02:38.020 回答
0

编辑答案:它基于您的参数的命名约定。看看这个链接并按照他们如何设置“oldName”参数。

于 2010-12-18T13:15:19.387 回答