ExtJS前台可以接收到多个后台的返回值吗?关于登录验证的,加分了!

cart55free99 2010-10-07 03:38:40
以前问过,后来出了点插曲,搁置了。
我想接收后台返回2个值,一个是 success标志, 还有一个是用户名。
很多人提议用Ext request
前面不管用什么 success部分的处理应该还是一样的吧

问题就在这里===================================================================
           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>
...全文
385 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Icepoint_chongqing 2010-10-13
  • 打赏
  • 举报
回复
后台输出json格式
cart55free99 2010-10-13
  • 打赏
  • 举报
回复
是Json格式的
cart55free99 2010-10-12
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 showbo 的回复:]

刷新当前页可以用
JScript code
window.location.reload();


java不知道,ext不太会,等别人帮你解决吧
[/Quote]

根据这个想了一个偏方得到了我想要的效果,但是我爱是想知道如何接受后台传来的两个值
cart55free99 2010-10-12
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 fancy161 的回复:]

JScript code

success : function(result, request) {
var jsonData = Ext.util.JSON
.decode(result.responseText);……
[/Quote]

那后台怎么写呢?
PrintWrite要写success 还有写nickName呢
fancy161 2010-10-08
  • 打赏
  • 举报
回复

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
});

得到用户名用 jsonData.nickname就OK了
hoojo 2010-10-08
  • 打赏
  • 举报
回复
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();


java不知道,ext不太会,等别人帮你解决吧
cart55free99 2010-10-07
  • 打赏
  • 举报
回复
怎么格式全乱了?

52,780

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧