我正在从事一个Struts2项目。我在项目中创建了URL,并使用标签传递了参数。我的问题是如何阅读动作中的参数?另外,如果这样做,我也可以将参数视为查询字符串。我问是因为我无法做到,我在其中一个教程中看到了它。

有帮助吗?

解决方案

通常,您将通过在操作中使用字段(由设置器公开)在操作中的参数进行交互。在我的示例struts2操作中假设以下URL图:

URL

http:// localhost/myaction?firstName = sonoftheearth

动作代码

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}

其他提示

编辑答案:它基于您的参数的命名约定。看看这个 关联 并遵循它们设置“ oldName”参数的方式。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top