Ext+JSP实现数据提交

[size=large]form组件实现数据的提交和验证!这里讲的主要是后台验证,和服务器脚本的交互!
我用的是EXT2.2.1版本,比2.0版本配置项功能更强!
数据提交用到的是submit函数!继承自Action,其自身多了一个clientValidation 配置项,表示是否设置前台验证!
我这里就讲了数据的提交,至于数据的加载基本上是一样的配置!自己参照API手册,主要是熟悉后台数据生成格式!JSON,并且success和data是必须的!
[/size]

action.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>action.html</title>
<style type="text/css">
body{background-color:#777777}
#form-ac{width: 350px;margin-left: auto;margin-right: auto;}
</style>
<link rel="stylesheet" type="text/css" href="../Ext/resources/css/ext-all.css" />
<script type="text/javascript" src="../Ext/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="../Ext/ext-all.js"></script>
<script type="text/javascript" src="action.js"></script>
</head>
<body>
<div id="form-ac"></div>
</body>
</html>


action.js

Ext.onReady(function(){
Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'qtip';
var panel = new Ext.form.FormPanel({
width:250,
height:170,
animCollapse :true,
title:'Action实现数据提交',
renderTo : 'form-ac',
frame:true,
collapsible :true,
items:[{
xtype:'fieldset',
title:'数据提交测试',
autoHeight:true,
items:[{
xtype:'textfield',
allowBlank:false,
blankText:'UserName不能为空!',
fieldLabel:'UserName',
name:'userName',
anchor : '95%'
},{
xtype:'textfield',
allowBlank:false,
blankText:'Pssword不能为空!',
fieldLabel:'Pssword',
name:'pass',
inputType:'password',
anchor : '95%'
}]
}],
buttons:[{
text:'提交',
handler:function(){
if(panel.form.isValid()){
panel.form.submit({
clientValidation :true,//是否实行前台验证
method:'GET',//发送发送方式 GET,POST
waitMsg :'正在登陆.....请等待...',//提交信息时候等待信息
waitTitle :'登陆',//提交信息时候等待信息的标题
url:'login.jsp',//提交页面
timeout :200,//超时的秒数
success:function(form,action){//验证成功的执行函数
Ext.Msg.alert('提示','登陆成功,userName:'+action.result.data.userName+",Pssword:"+action.result.data.password);
//实现登陆成功后的更多操作可以到这里,比如实现跳转或者设置session
},
failure :function(form,action){//验证失败的执行函数
Ext.Msg.alert('提示','登陆失败,原因:'+action.result.errors.rs);
//这里也可以做相应的处理,比如设置错误的次数,多少次之后设置锁定帐号或者IP,这方面我以后讲解
}
});
}
}
},{
text:'重置',
handler:function(){
panel.form.reset();
}
}]
})
})

login.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
String password = request.getParameter("pass");
String userName = request.getParameter("userName");
String msg = "";
if("hello".equals(userName)&&"world".equals(password)){
msg="{success:true,data:{userName:'"+userName+"',password:'"+password+"'}}";
//成功时候的返回信息
}else{
msg="{success:false,errors:{rs:'password和userName不匹配,请重新输入'}}";
//失败时候的返回信息
}
response.getWriter().write(msg);
%>


虽然简单也传上原代码:
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值