Basic code:
<script>
Ext.onready (function () {ext.create (' Ext.form.Panel ', {title: ' Login ', Bodypadding:5, width:350,//will go through AJAX Submit to this URL URL: ' ${pagecontext.request.contextpath}/back/login.do ',//The Form field fields will be vertically arranged, full width frame:true, Layout: ' Auto ',//The fields DefaultType: ' TextField ', items: [{fieldlabel: ' username ', Name: ' Name ', Allowblank:false,blanktext: ' username cannot be empty '},{Fieldlabel: ' Password ', inputtype: ' Password ', name: ' pwd ', Allowblank:false,blanktext: ' Password cannot be empty '},{Fieldlabel: ' User type ', Name: ' Type ', Allowblank:false, Hidden:true,//Hide component default false value:1//form default}],//Reset and save button. Buttons: [{text: ' Reset ', Handler:function () {this.up (' form '). GetForm (). reset (); }}, {text: ' Save ', Formbind:true,//only enabled once the form is valid disabled:true, ha Ndler:function () {var form = this.up (' form '). GetForm (); if (Form.isvalid ()) {Form.submit ({success:function (form, action) { Ext.Msg.alert (' Hint information ', ACTION.RESULT.RESTMSG); }, Failure:function (form, action) {Ext.Msg.alert (' hint info ', ACTION.RESULT.RESTMSG ); } }); }}], RenderTo:Ext.getBody ()}); }); </script>
No added field check, verification code, password encryption, and so on, just the implementation of the pure login function, the specific details temporarily ignored!
Login.do the corresponding program:
/*** Login * *@return */@RequestMapping ("/login") @ResponseBody Public voidLogin (@RequestParam string name, @RequestParam string pwd, @RequestParamintType,writer Writer) {String valmsg=""; Try{User User=NewUser (); User.setuname (name); User.setpwd (PWD); User.setutype (type); User GetUser=userservice.queryuser (user); if(getuser!=NULL) {valmsg=showresultmsg (true, "Login Successful"); //Jump to homepage}Else{valmsg=showresultmsg (false, "User does not exist!"); } } Catch(Exception e) {e.printstacktrace (); Valmsg=showresultmsg (true, "Login Failed"); }finally { Try{writer.write (valmsg); } Catch(IOException e) {e.printstacktrace (); } } }
Results returned:
{"Result":true, "restmsg": "Login successful!"}
[ExtJS] ExtJs4.2 Form form Submission