简体   繁体   English

如何访问struts2中的url参数

[英]How to access url parameters in struts2

I am working on a struts2 project. 我正在开发一个struts2项目。 I have created url with in my project and have passed parameters using tags. 我在我的项目中创建了url并使用标签传递了参数。 My question is how do i read the parameter in the actions? 我的问题是如何读取动作中的参数? also if do the same would i be able to see the parameters as query string. 如果这样做,我将能够将参数看作查询字符串。 i ask because i am not able to and i saw it in one of the tutorials. 我问,因为我无法在一个教程中看到它。

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映射到我的示例Struts2操作:

URL 网址

http://localhost/myAction?firstName=SonOfTheEARTh HTTP://本地主机/ 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 JSP

Using Struts tags: <s:property value="firstName"/> 使用Struts标签: <s:property value="firstName"/>

Using JSP EL/JSTL: ${action.firstName} 使用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. 看看这个链接,并按照他们如何设置“oldName”参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM