使用Ajax将数据传递给action类

时间:2015-11-05 00:41:54

标签: java jquery ajax jsp struts2

我需要帮助使用jQuery ajax将表单数据从JSP传递到Struts2操作类。我已经给出了以下代码。

我做错了什么?

JSP:

<form>
Enter email address: <input type="text" id="processPasswordForm" name="password"/>
<input onClick="emailPassword();" type="button" class="btn btn-primary" value="Search" />
</form>

的Ajax:

function emailPassword() {
    var password = $('#processPasswordForm').val();
    alert(password);
    $.ajax({
        url: "email-password.action",
        method: "POST",
        data: {"passwordEmail": password},
        async: true,
        success: function() {
            alert("Success");
        }
    });

我的动作类:

private String passwordEmail = null;

public String getPasswordEmail() {
    return passwordEmail;
}

public void setpasswordEmail(String passwordEmail) {
    this.passwordEmail = passwordEmail;
}

@Action(value="email-password", results={
    @Result(name="success", type="httpheader", params={
        "status", "200"
    })                                                  
})
public String sendPassword() throws Exception {
    if (this.passwordEmail != null) {
        EmailUtility.sendPasswordEmail(passwordEmail); 
    }

    return SUCCESS;
}

错误:

 Uncaught ReferenceError: emailPassword is not defined in the browser console.

0 个答案:

没有答案