Recently learned the integration of SSH2 (Struts2+spring+hibernate), began to try to write a landing interface, the results found: if the use of Struts2 to page jump, the effect of the page is not good, at the same time can not be local refresh (that is, asynchronous submission verification).
So, I began to search the Internet solution, some say through a hidden iframe to achieve the effect, when I always feel trouble and not practical. Later asked the teacher, told me to use Ajax to achieve the desired effect, I found that there are many examples on the web are Ajax, but the missing is SSH2 (integrated) and AJAX integration (Ajax using the jquery framework).
Tell me about the effect I want:
Login page Click to submit after the background verification;
Validation successfully jumps to index. JSP;
Validation fails to execute a jquery script prompt user on this login page;
Required Packages:
SSH2 is used in the package, you also need to struts2 the following package:
Commons-beanutils-1.8.0.jar
Commons-collections-3.1.jar
Commons-fileupload-1.3.1.jar
Commons-io-2.2.jar
Commons-lang-2.4.jar
Commons-lang3-3.1.jar
Commons-logging-1.1.3.jar
Ezmorph-1.0.6.jar
Freemarker-2.3.19.jar
Json-lib-2.3-jdk15.jar
Ognl-3.0.6.jar
Struts2-core-2.3.16.3.jar
Struts2-json-plugin-2.3.16.3.jar
Xwork-core-2.3.16.3.jar
OK, start pasting code:
login.jsp
Account: <input id= "user" name= "user" type= "text"/><br/>
Password: <input id= "PassWord" name= "PassWord" type= "PassWord"/><br/>
<input id= "button" type= "button" value= "Submit"/>
</body>
Loginaction.java
Publicclass Loginaction extends Actionsupport {
//Use @resource annotation inject condition property name to be consistent with ref to
@Resource
Fuserservice Fuserserviceimp;
@Resource
FUser FUser;
Private String User;
Private String PassWord;
Private String result;
Public String GetResult () {
returnresult;
}
Publicvoid SetUser (String User) {this
. user = user;
}
Publicvoid SetPassword (String PassWord) {this
. PassWord = PassWord;
}
Public String Execute () throws Exception {
HttpServletRequest request = Servletactioncontext.getrequest ();
Get AJAX-handed data directly using the foreground's property name.
Fuser.setuseremail (User);
Fuser.setuserpassword (PassWord);
if (Fuserserviceimp.checkuser (fUser)!=null) {
//data returned to Ajax
This.result = "true";
} else{
This.result = "false";
}
Return "Success";
}
Struts.xml
<?xml version= "1.0" encoding= "UTF-8"?>
<struts>
<!-This is the package
to configure struts when we configure SSH--> <package name= "Struts" extends= "Struts-default" >
<action name= "Login" class= "loginaction" >
</action>
</package>
<!-in order for Ajax to invoke the action in spring to configure AJAX package-->
<package Name= "Ajax_json" extends= "Json-default" >
<!-the ID of this place is the value of the Ajax URL, class references the id-->
of the spring configuration action <action name= "Login" class= "loginaction" > <result name= "Success" type=
"json"/>
</action >
</package>
</struts>
Other SSH2 frameworks are consolidated without changes so that the jquery framework Ajax can be integrated into the SSH2 framework for use!
The above content is individual thought, if has the wrong place welcome to me to leave a message, I will in the first time and everybody obtains the contact, thanks everybody has been to the cloud Habitat Community website support.