![](/img/trans.png)
[英]How to call a method in Struts2 Action Class method with javascript
[英]how to call method in action class in javascript using struts2 framework?
我正在嘗試在jsp中的按鈕單擊事件上的javascript函數中的動作類中調用方法。我正在使用struts 2.你能告訴我怎么做嗎? 當用戶單擊“提交”按鈕時,我想調用ListAlgorithmAction類中的一個函數。
function alertselected (){
var x = document.getElementById ( "select_name" ).selectedIndex;
var y = document.getElementById ( "select_name" ).options;
var id = y [x].index;
redirect(id);
}
function redirect(x){
document.getElementById ( "param_ID" ).value = x;
document.forms ["./ListAlgorithmAction"].submit ();
}
我不認為這與Struts2有關,因為Struts2與您調用動作類的方式無關,無論它是通過Java腳本形式提交,ajax還是通過簡單形式提交。
我相信你的jsp中有某種形式
<s:form action="myAction" name="myForm">
some data
</s:form>
點擊可以做類似的事情
function redirect(x){
document.getElementById("param_ID").value=x;
document.myForm.action="ListAlgorithmAction";
document.myForm.submit();
}
這只是基於您的輸入的解決方案,如果您能夠更多地定義問題,則可以有更多解決方案
對於類似的實現,我們曾經使用http://directwebremoting.org/dwr/index.html(DWR )。 您可以嘗試一下..如果您實現量很大,我建議您集成此框架
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.