extjs와java 백그라운드 간의 상호작용 (로그인 실례)

2407 단어 ExtJs
로그인 하나.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);
	}
%>

좋은 웹페이지 즐겨찾기