52,780
社区成员
发帖
与我相关
我的任务
分享 function login(){//提交表单
loginForm.form.submit({
clientValidation: true,
waitMsg: '正在登陆系统请稍后',
swaitTitle: '提示',
url: '../user.do?m=login',
method: 'POST',
success: function(form, action){
windowLogin.hide();
Ext.Msg.alert('提示', '系统登陆成功');
//window.history.go(0);
//document.execCommand('Refresh');//本想直接刷新
//但是没有效果
//。。。。。。。怎么接受后台传出的用户名?????????????????
//用action.result.responseText 吗?可是我想返回2个 怎么区别呢?
Ext.getCmp("toolbar_login").setText("用户名。。。");
},
failure: function(form, action){
Ext.Msg.alert('提示', '系统登陆失败,原因:' + action.failureType);
}
});
}public ActionForward login(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
UserForm userForm = (UserForm) form;
String mappingForward = "";
int listSize = userService.findByUsername(
userForm.getUser().getUsername()).size();
System.out.println("login listSize " + listSize);
TbUser user = null;
boolean isSuccess = false;
if (listSize != 0) {
user = (TbUser) userService.findByUsername(
userForm.getUser().getUsername()).get(0);
if (user.getPassword().equals(userForm.getUser().getPassword())) {
request.getSession().setAttribute("loginUser", user);
System.out.println("has login");
isSuccess = true;
try {
response.setContentType("text/json;charset=UTF-8");
PrintWriter out = response.getWriter();
//这里难道是这样写吗?这样ProgessBar会一直加载呢?????????????????????
//out.write()只能有一句 要不然总是无限加载
// out.write("{nickname:"+user.getNickname()+"}");
out.write("{success:" + isSuccess + "}");
// out.flush();
// out.close();// 清空、关闭
} catch (IOException e) {
e.printStackTrace();
}
}
} else {
isSuccess = false;
}
return null;
}<%@ page language="java" pageEncoding="GBK" import="myBlog.dao.*"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>MyAjax1.jsp</title>
<link rel="stylesheet" type="text/css"
href="../extJS/ext-2.3.0/resources/css/ext-all.css" />
<script type="text/javascript"
src="../extJS/ext-2.3.0/adapter/ext/ext-base.js">
</script>
<script type="text/javascript" src="../extJS/ext-2.3.0/ext-all.js">
</script>
</head>
<body>
<%
TbUser loginUser = (TbUser) request.getSession().getAttribute(
"loginUser");
if (loginUser == null) {
%>
<script type="text/javascript">
Ext.onReady( function() {
Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'side';
initHeadToolBar();
initForm();
initWindow();
windowLogin.hide();
});
var headToolBar;
function initHeadToolBar() {
headToolBar = new Ext.Toolbar( {
applyTo :'toolbar',
width :400
});
headToolBar.add( {
id :'toolbar_login',
text :'login',
handler : function() {
windowLogin.show();
}
});
}
/*login窗口 */
var windowLogin;
function initWindow(){
alert("initn Window");
windowLogin = new Ext.Window({
layout: 'fit',
width: 380,
height: 280,
resizable: false,
closeAction: 'hide',
renderTo:Ext.getBody(),
items: [loginForm]
});
}
/* 设置 loginForm */
var loginForm;
function initForm(){
alert("initnForm");
loginForm = new Ext.form.FormPanel({
width: 230,
frame: true,
items: [
new Ext.form.TextField({
fieldLabel: '用户名',
name: 'user.username',
value: 'raku@r.com',
allowBlank: false,
vtype: 'email'
}), new Ext.form.NumberField({
fieldLabel: '密码',
name: 'user.password',
value: '123',
inputType: 'password',
allowBlank: false
})],
buttons: [
new Ext.Button({
text: '登陆',
handler: login
}), new Ext.Button({
text: '重置',
formBind: true,
handler: function(){
loginForm.getForm().reset();
}
})]
});
}
/* 表单提交动作 */
function login(){//提交表单
loginForm.form.submit({
clientValidation: true,
waitMsg: '正在登陆系统请稍后',
swaitTitle: '提示',
url: '../user.do?m=login',
method: 'POST',
success: function(form, action){
windowLogin.hide();
//Ext.Msg.alert(action.result.responseText);
Ext.Msg.alert('提示', '系统登陆成功');
//window.history.go(0);
//document.execCommand('Refresh');
Ext.getCmp("toolbar_login").setText(action.result.responseText);
},
failure: function(form, action){
Ext.Msg.alert('提示', '系统登陆失败,原因:' + action.failureType);
}
});
}
</script>
<%
} else {
%>
Hi!
<%=loginUser.getUsername()%>
welcome!!
<%
}
%>
<div id='toolbar'>
</div>
<div id='form'>
</div>
</body>
</html>
success : function(result, request) {
var jsonData = Ext.util.JSON
.decode(result.responseText);
if (jsonData.success == 'true') {
Ext.Msg.show({
title : '注意',
msg : successMsg,
buttons : Ext.Msg.OK,
icon : Ext.MessageBox.INFO
});
loginForm.getForm().submit({
clientValidation: true,
waitMsg: '正在登陆系统请稍后 ',
swaitTitle: '提示 ',
url: '../user.do?m=login ',
method: 'POST ',
success: function(form, action){
windowLogin.hide();
alert(action.result);
alert(Ext.encode(action.result));
alert(action.result.success);//success和后台的数据对应,不需要转换
alert(action.result.nickname);
}
});
window.location.reload();