文档库 最新最全的文档下载
当前位置:文档库 › ExtJSStruts2提交数据

ExtJSStruts2提交数据

ExtJs3.0 Struts-2.1.8.1实现用户登录:
首相加入Struts支持:
加入struts2-json-plugin-2.1.81.jar 此包可以在Struts-2.1.8.1\lib目录下找到
配置struts.xml文件:
主要配置如下
需要注意package 的extends="json-default"

"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"https://www.wendangku.net/doc/9518073995.html,/dtds/struts-2.0.dtd">














编写User类:
package com.xq24.model;

public class User {
private int id;
private String username;
private String password;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
https://www.wendangku.net/doc/9518073995.html,ername = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}

}

编写LoginAction类:
package com.xq24.action;

import com.opensymphony.xwork2.ActionSupport;
import https://www.wendangku.net/doc/9518073995.html,er;

public class LoginAction extends ActionSupport {

/**
*
*/
private static final long serialVersionUID = 1L;
private boolean success;
private String message;
private User user;
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
if(user.getUsername().equals("root") && user.getPassword().equals("root")) {
this.success = true;
this.message = "username:" + user.getUsername() + "|password:" + user.getPassword();
}else {
this.success = false;
this.message = "不存在的用户名或密码!";
}
System.out.println(user.getUsername());
System.out.println(user.getPassword());
return super.execute();
}
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) {
https://www.wendangku.net/doc/9518073995.html,er = user;
}

}
login.jsp中主要代码:




login.js中的内容:
Ext.onReady(function(){
Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = "side";
var s

imple = new Ext.FormPanel({
labelWidth:40,
baseCls:"x-plain",
defaultType:"textfield",
defaults:{width:180},
items:[{
fieldLabel:"帐号",
name:"https://www.wendangku.net/doc/9518073995.html,ername",
allowBlank:false,
blankText:"用户名不允许为空"
},{
inputType:"password",
fieldLabel:"密码",
name:"user.password",
allowBlank:false,
blankText:"密码不允许为空?"
}],
buttons:[{
text:"登录",
type:"submit",
handler:function(){
if(simple.form.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 < 13; i++) {
setTimeout(f(i), i * 150);
}
simple.form.doAction("submit",{
url:"login.action",
method:"post",
params:"",
success:function(form, action){
document.location='success.jsp';
Ext.Msg.alert("提示",action.result.message);
},
failure:function(form, action){
Ext.Msg.alert('提示', action.result.message);
}
});
}
}
},{
text:"重置",
handler:function(){
simple.form.reset();
}
}]
});
var _window = new Ext.Window({
title:"登录窗口",
layout:"fit",
width:280,
height:150,
plain:true,
bodyStyle:"padding:10px;",
maximizable:false,
closeAction:"close",
closable:false,
collapsible:true,
plain:true,
buttonAlign:"center",
items:simple
});
_window.show();
});
以上就可以实现一个简单的用户登录功能:

相关文档