1. The client transmits data to login.action through the $.ajax () method;
2, where the Execute () method in action returns a value of NULL and passes "servletactioncontext.getresponse (). Getwriter (). Print (result); "Method to upload data to jquery.
Loginaction.java
Public throws Exception { booleanfalse; if (username.equals (password)) { true; } Servletactioncontext.getresponse (). Getwriter (). Print (result); return NULL ;}
Login.js
$.ajax ({ "post", "Login.action", Data: $ ("#form1"). Serialize (), function(data, textstatus) { if (data = = "true") { alert ("Success"); } if (data = = "false") { alert ("failure");}} );
Struts.xml
<name= "Struts2" namespace= "/" extends= " Struts-default "> <name=" Login " class = "Cn.hist.water.action.LoginAction"></action> </package>
Reference: http://blog.163.com/asd_wll/blog/static/210310402011103001241985/
The combination of Struts2 and Jquery.ajax ()