java struts2中如何访问url参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4478147/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to access url parameters in struts2
提问by SonOfTheEARTh
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.
我正在做一个 struts2 项目。我在我的项目中创建了 url 并使用标签传递了参数。我的问题是如何读取动作中的参数?此外,如果这样做,我是否能够将参数视为查询字符串。我问是因为我不能,我在其中一个教程中看到了它。
回答by Steven Benitez
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:
通常,您将通过在操作上使用由 setter 公开的字段来与操作中的参数进行交互。假设以下 URL 映射到我的示例 Struts2 操作:
URL
网址
http://localhost/myAction?firstName=SonOfTheEARTh
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
JSP
Using Struts tags: <s:property value="firstName"/>
使用 Struts 标签: <s:property value="firstName"/>
Using JSP EL/JSTL: ${action.firstName}
使用 JSP EL/JSTL: ${action.firstName}