struts2 结合extjs实现的一个登录实例
2020-12-13 03:38
阅读:488
YPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
标签:java extjs struts2 myeclipse 实例
一、先搭建好struts2,可以通过myeclipse快速搭建。
二、再导入extjs所需的库文件。
三、写一个实体类User
package com.ext.model; public class User { private Integer id; private String username; private String password; public Integer 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; } }四、写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="你的账号是:"+user.getUsername()+"密码是:"+user.getPassword(); }else{ this.success=false; this.message="对不起,未授权的用户不能登录改系统"; } 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; } }五、struts.xml如下所示:
六、login.jsp
七、login.jsInsert title here
Ext.onReady(function(){ Ext.QuickTips.init(); Ext.form.Field.prototype.msgTarget="side"; var form1=new Ext.FormPanel({ labelWidth:40, baseCls:‘x-plain‘, defaults:{width:180}, items:[{ xtype:‘textfield‘, fieldLabel:"用户名", id:"txtName", name:‘user.username‘, allowBlank:false, blankText:"用户名不能为空!" },{ xtype:‘textfield‘, fieldLabel:"密码", allowBlank:false, blankText:"密码不能为空!", name:‘user.password‘, inputType:‘password‘ }], buttons:[{ text:"提交", type:‘submit‘, handler:function(){ if(form1.getForm().isValid()) { Ext.MessageBox.show({ title:‘请等待‘, msg:‘正在加载‘, 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八、登录成功的index页面就不写了。
用extjs实现页面间的跳转开始学有点麻烦,注意红色部分。
struts2 结合extjs实现的一个登录实例,搜素材,soscw.com
struts2 结合extjs实现的一个登录实例
标签:java extjs struts2 myeclipse 实例
原文地址:http://blog.csdn.net/primary_wind/article/details/25708511
评论
亲,登录后才可以留言!