如何在Struts2中访问URL参数 [英] How to access url parameters in struts2

查看:359
本文介绍了如何在Struts2中访问URL参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个struts2项目.我在项目中创建了url,并使用标签传递了参数.我的问题是如何读取动作中的参数?如果做同样的话,我也可以看到参数作为查询字符串.我问是因为我做不到,而且我在其中一个教程中看到了它.

I am working on a struts2 project. I have created url with in my project and have passed parameters using tags. 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.

推荐答案

通常,您将通过使用设置方法公开的操作字段来与操作中的参数进行交互.假定以下URL映射到我的示例Struts2操作:

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

操作代码

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"/>

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

使用JSP EL/JSTL:${action.firstName}

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

这篇关于如何在Struts2中访问URL参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆