如何使用struts2框架在javascript中调用动作类中的方法? [英] how to call method in action class in javascript using struts2 framework?

查看:33
本文介绍了如何使用struts2框架在javascript中调用动作类中的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在jsp中的按钮单击事件的javascript函数中调用动作类中的方法.我正在使用struts 2.你能告诉我怎么做吗?ListAlgorithmAction 类中有一个函数,我想在用户单击提交按钮时调用它.

I am trying to call a method in action class in javascript function on button click event which is in jsp.I am using struts 2.could you tell me how to do this? There is a function in ListAlgorithmAction Class which I want to call when the user clicks submit button.

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 独立于您调用 action class 的方式,无论是通过 java-script form submit、ajax 还是通过简单的表单提交.

I do not think this is something related to Struts2 ,since struts2 is independent of the way you call action class be it by java-script form submit,ajax or by simple form submit.

我相信你的jsp中有某种形式

i believe you have some form in your jsp like

<s:form action="myAction" name="myForm">
  some data

</s:form>

点击你可以做类似的事情

on click you can do something like

function redirect(x){
    document.getElementById("param_ID").value=x;
    document.myForm.action="ListAlgorithmAction";
     document.myForm.submit();
    }

这只是基于您的输入的解决方案,如果您能够更多地定义您的问题,可能还有更多

This is just solution based on your inputs and there can be many more if you able to define your problem more

这篇关于如何使用struts2框架在javascript中调用动作类中的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆