2014-10-19 101 views
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> 

在按钮的点击,PopUpActiongetDealersByGroup方法应该被调用,并且在使用中传递的值,即"reportGroup"一个SQL查询。 但是,根据上述JavaScript函数setDealers,只有警报命令正在执行,并且所需的值没有传递给动作类。

是否有遗漏/或错误struts.xml

回答

1

首先,你已经在代码==一个错字VS =

其次,这听起来像重定向到行动,调用动作使用s:action$.ajax()看到example

Trird,对于URL,更好地使用s:url标记来构建url。

var url = "<s:url action='getDealersByGrouppopUpAction'/>"+"?reportGroup="+rep_value; 
window.location=url; 
相关问题