extjs和java后台间的交互(登录实例)

一个login.jsp界面
一个ext_login.js:

Ext.onReady(function(){
Ext.QuickTips.init(); //初始化信息提示
var form = new Ext.FormPanel({
title:'user login',
width:'240px',
height:'200px',
renderTo:'loginDiv',
frame:true,
labelWidth:50,
labelAlign:'right',
items:[{
id:'username', //为输入框加个id
xtype:'textfield',
name:'username',
fieldLabel:'account',
allowBlank:false,
blankText:'account cannot be null'
},{
id:'password',
xtype:'textfield',
name:'password',
inputType:'password',
fieldLabel:'password',
allowBlank:false,
blankText:'account cannot be null'
}],
buttons:[{
text:'login',
id:'mybutton',
listeners:{ //关键:btn的click函数
"click":function(){
if(form.getForm().isValid()){
Ext.Ajax.request({
method:'post',
url:'ajaxLoginServer.jsp',
params:{
username:Ext.getCmp('username').getValue(), //获得filefield中的值
password:Ext.getCmp('password').getValue()
},
callback:function(options,success,response){
Ext.Msg.alert('notice',response.responseText);
}
});
}
}
}
}]
});
form.show();
});

一个ajaxLoginServer:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%
String username = request.getParameter("username");
String password = request.getParameter("password");
if(username == null){response.getWriter().write("username == null");}
if(username.equals("")){response.getWriter().write("username.equals-null");}
if(username.equals("guanlin") && password.equals("123")){
response.getWriter().write("success!");
}else{
response.getWriter().write("failed! nihao" + username);
}
%>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值