How to pass parameters in struts2?
In Struts2, parameters can be passed in two ways: through URL parameters and form parameters.
- what is the URL of the website?
- Please provide me with your final decision.
For example, creating a URL with parameters:
<s:url var="myUrl" action="myAction">
<s:param name="param1" value="value1" />
<s:param name="param2" value="value2" />
</s:url>
Then use that URL in the
<s:a href="%{myUrl}">Link</s:a>
<s:submit value="Submit" action="%{myUrl}" />
In Action, you can receive passed values by defining corresponding parameters.
private String param1;
private String param2;
// Getter and setter methods
public String execute() {
// 使用接收到的参数进行业务处理
return "success";
}
- Enter your name:
For example, creating a form with parameters:
<s:form action="myAction">
<s:textfield name="param1" label="Param1" />
<s:textfield name="param2" label="Param2" />
<s:submit value="Submit" />
</s:form>
In Action, you can receive values from a form by defining corresponding parameters.
private String param1;
private String param2;
// Getter and setter methods
public String execute() {
// 使用接收到的参数进行业务处理
return "success";
}
It is important to ensure that the parameter names match those defined in the Action in order to correctly receive the passed values.