【问题标题】:how to call a particular method of action of Struts2 through jquery ajax如何通过jquery ajax调用Struts2的特定动作方法
【发布时间】:2016-06-29 08:29:18
【问题描述】:

我是 jquery 和 ajax 的新手。我想在 Struts2 中调用动作“LoginAction”的特定方法“注销”。我收到一个错误

没有为命名空间 / 和操作名称 logoutLoginAction 映射操作。

我的ajax代码是:

function signout(){
     $.ajax({   
         type: "POST",
         assync:false,
         url: "logoutLoginAction.action",
         success: function(messageResponse) {                   
         response=messageResponse;
         alert(response);
     }});        
}

【问题讨论】:

  • 您的配置中有logoutLoginAction 操作吗?如果你不这样做,你可以创建一个。

标签: jquery ajax jsp struts2 struts-action


【解决方案1】:

您想要实现的目标称为Wildcard mapping

在你的情况下应该是这样的:

<action name="/*LoginAction" class="foo.bar.LoginAction" method="{1}">
    <result>{1}.jsp</result>
</action>

如果你调用logoutLoginAction,注销会被当作{1},然后调用logout()方法,返回logout.jsp文件。

或者,您可以为 Java 文件的每个方法定义一个操作,as described here

【讨论】:

  • 谢谢,您的回答有助于澄清我的疑问。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-10-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多