日期:2014-05-17  浏览次数:20687 次

jquery中post
我通过jquery中的$.post()方法请求一个struts2的一个action,返回结果出现些问题,希望高手指点迷津......
JS代码
JScript code

$(document).ready(function() {
    $("#submit").click(function() {
        var psw = $("#password");
        var username = $("#username").val();
        var password = hex_md5(psw.val());
        alert(psw.val()+":"+password);
        $.post("Login.action",{"username":username},function(data){alert(data);});
        alert("123");
    }

    );
}


JavaAction代码
Java code

package com.action;

import com.opensymphony.xwork2.ActionSupport;

public class Login extends ActionSupport{
    private String username;
    private String password;
    public String execute() throws Exception {    
        
        return SUCCESS;
    }
    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    
    public String catchinfo(){
        
        System.out.println("进入action......");
        System.out.println(username);
        System.out.println("离开action......");
        return "zhongguo";
    }

}



JSP代码
HTML code

<html>
    <head>
        <script type="text/javascript" src="<%=path %>/js/jquery-1.7.2.js">
</script>
        <script type="text/javascript" src="<%=path %>/js/md5.js">
</script>
        <script type="text/javascript" src="<%=path %>/js/login.js">
</script>
    </head>

    <body>
        <div align="center">
            user login
            <br />
            <br />
            username:
            <s:textfield name="username"></s:textfield>
            <br />
            <br />
            password:
            <s:password name="password"></s:password>
            <br />
            <br />
            <s:submit value="提交" id="submit"></s:submit>

        </div>
    </body>
</html>





返回结果没有弹出

控制台的结果是

HTML code

进入action......
da
离开action......
2012-7-6 16:26:59 com.opensymphony.xwork2.util.logging.jdk.JdkLogger error
严重: Could not find action or result
/MyPrj/pages/Login.action
No result defined for action com.action.Login and result zhongguo
    at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:375)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:277)
    at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)






------解决方案--------------------
楼主 struts配结果了吗No result defined for action com.action.Login and result zhongguo
------解决方案--------------------
楼主你没有配struts返回结果,或者是你写错了
No result defined for action com.action.Login and result zhongguo<