1
我试图通过单击按钮(非提交按钮)将文本字段的值作为URL参数从JSP传递给动作类并找到该链接中的解决方案:Onchange event in Struts2。在JSP中将参数传递给Struts 2中的动作类
我已执行了该链路,即提到的所有步骤:
- 创建用于
onClick
事件 - 功能即
setDealers
内一个JavaScript功能,即"reportGroup"
的值传递给动作类,如下所示
function setDealers(){
var rep_value=document.getElementById("reportGroup").value;
alert("Value is"+rep_value);
window.location=="getDealersByGrouppopUpAction?reportGroup="+rep_value;
alert("Just a check")
}
- 创建在动作类中名称为
"reportGroup"
,即PopUpAction.java
,其中有getter和setter。
也支持这一切,我在struts.xml
以下配置:
<action name="*popUpAction" class="popUpAction" method="{1}" >
<!--this will call a desired method present inside action class -->
...
...
</action>
在按钮的点击,PopUpAction
类getDealersByGroup
方法应该被调用,并且在使用中传递的值,即"reportGroup"
一个SQL查询。 但是,根据上述JavaScript函数setDealers
,只有警报命令正在执行,并且所需的值没有传递给动作类。
是否有遗漏/或错误struts.xml
。