只是想知道是否有人见过或写过调用 Struts2 Actions 的客户标签。
我正在寻找的是这样的:-
<s:button value="Click Me!" action="thisIsMyAction" >
<s:param name="productId" value="%{productId}" />
<s:param name="userId" value="%{userId}" />
</s:button>
这样在 Action 中你就有了
public String thisIsMyAction() {
String productId = getServletRequest.getParameter("productId");
String userId= getServletRequest.getParameter("userId");
// Do some stuff here.
return SUCCESS;
}
原因是,我们不想使用 href 或图像,而且我们并不总是提交表单。
提前干杯
最佳答案
您可以创建一个带有两个隐藏参数和一个提交类型按钮的表单。
<s:form action="myAction">
<s:hidden name="productId" value="%{productId}" />
<s:hidden name="userId" value="%{userId}" />
<s:submit value="Click me!" type="button"/>
</s:form>
在我的操作中,您使用相关的 getter 和 setter 声明属性 productId 和 userId。
关于struts2 - 用于按钮调用操作的 struts 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11155343/