How to call a method in Struts2 Action Class method with javascript(如何使用javascript调用Struts2 Action Class方法中的方法)
问题描述
我们目前使用以下 javascript 在其中一个字段值更改时提交表单.
We currently use the following javascript to submit the form when one of the field values change.
var url = "project/location/myAction.action?name="+ lname ;
document.forms[0].action = url;
document.forms[0].submit();
调用以下 Struts2 动作
which calls the following Struts2 action
<action name="myAction" class="project.location.NameAction">
<result name="success" type="tiles">myAction</result>
</action>
然后转到 Action 类 NameAction
的 execute()
方法,我必须检查表单是否是从 javascript 提交的.
which then goes to the execute()
method of the Action class NameAction
where I have to check to see if the form was submitted from the javascript.
我更愿意直接从 javascript 调用 NameAction
中的 findName()
方法.换句话说,我希望 javascript 的行为类似于以下 jsp 代码.
I would prefer to call the findName()
method in NameAction
directly from the javascript. In other words I want the javascript to act like the following jsp code.
<s:submit method="findName" key="button.clear" cssClass="submit" >
推荐答案
实现你想要的有不同的方法,但可能更简单的是将不同的动作映射到同一个动作类文件的不同方法,例如.带注释:
There are different ways to achieve what you want, but probably the simpler is to map different actions to different methods of the same action class file, eg. with annotations:
public class NameAction {
@Action("myAction")
public String execute(){ ... }
@Action("myActionFindName")
public String findName(){ ... }
}
或使用 XML:
<action name="myAction" class="project.location.NameAction">
<result name="success" type="tiles">myAction</result>
</action>
<action name="myActionFindName" class="project.location.NameAction" method="findName">
<result name="success" type="tiles">myAction</result>
</action>
然后在javascript中:
Then in javascript:
var url = "project/location/myActionFindName.action?name="+ lname ;
这篇关于如何使用javascript调用Struts2 Action Class方法中的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用javascript调用Struts2 Action Class方法中的方法
- Flexslider 箭头未正确显示 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- Fetch API 如何获取响应体? 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- 400或500级别的HTTP响应 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01