Struts2 a login instance implemented in conjunction with ExtJS

Source: Internet
Author: User

First, set up a good struts2, can be built quickly through the myeclipse.

Second, re-import the ExtJS required library files.

Third, write an entity class user

Package Com.ext.model;public class User {private Integer id;private string username;private string Password;public intege R GetId () {    return ID;} public void SetId (Integer id) {    this.id = ID;} 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;}}
Iv. Writing Loginaction

Package Com.ext.action;import Com.ext.model.user;import Com.opensymphony.xwork2.actionsupport;public class  Loginaction extends Actionsupport {Private Boolean success;private String message;private user user; @Override public String execute () throws Exception {//TODO auto-generated Method stub if (User.getusername (). Equals ("admin"            ) &&user.getpassword (). Equals ("admin")) {this.success= true;        This.message= "Your account number is:" +user.getusername () + "password is:" +user.getpassword ();            }else{This.success=false;        This.message= "Sorry, unauthorized users can not login to change the system";    } return SUCCESS; }public Boolean issuccess () {return success;} public void Setsuccess (Boolean success) {this.success = success;} Public String GetMessage () {return message;} public void Setmessage (String message) {this.message = message;} Public User GetUser () {return user;} public void SetUser (user user) {this.user = user;}}
v. Struts.xml is as follows:

Liu, login.jsp

<%@ page Language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" UTF-8 "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >
Seven, Login.js
Ext.onready (function () {Ext.QuickTips.init (); Ext.form.field.prototype.msgtarget= "side"; var form1=new ext.formpanel ({labelwidth:40, basecls: ' X-plain ', default s:{width:180}, items:[{xtype: ' TextField ', Fieldlabel: "username", ID: "Txtname", Name: ' User.usern        Ame ', Allowblank:false, Blanktext: "User name cannot be empty!" },{xtype: ' TextField ', Fieldlabel: "Password", Allowblank:false, Blanktext: "Password cannot be empty!", Name: ' Us Er.password ', InputType: ' Password '}], buttons:[{text: "Commit", type: ' Submit ', handler:                function () {if (Form1.getform (). IsValid ()) {Ext.MessageBox.show ({title: ' Please wait ',                msg: ' Loading ', Progresstext: ', width:300, Progress:true,                Closable: ' false ', Animel: ' loding '}); var f = function (v) {return function () {var I=V/11;                Ext.MessageBox.updateProgress (i, ");            }} for (Var i=1;i<33;i++) {setTimeout (f (i), i*1500);             }//Submit to Server Operation Form1.form.doAction (' Submit ', {url: ' login.action ', Method: ' Post ',                Success:function (form,action) {document.location= "index.jsp"; Ext.Msg.alert ("Login Successful!            ", action.result.message); }, Failure:function (form,action) {Ext.Msg.alert ("Login failed!            ", action.result.message);        }            });    }}}, {text: "Reset", Handler:function () {form1.getform (). reset ();}]}); var window = new Ext.window ({title: "Login Window", layout: ' Fit ', width:290, height:250, plain        : True, bodystyle: ' padding:10px ', Maximizable:false, Closeacton: ' Close ', Closable:false, Collapsible:true, buttonalign: ' CEnter ', Items:form1}); Window.show ();});


Eight, the login successful index page will not write.

Use ExtJS to achieve jumps between pages start learning a little trouble, pay attention to the red part.






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.