[ExtJS] ExtJs4.2 Form form Submission

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.