action添加信息后,返回给ExtJs是否成功问题

wxl1214471 2013-02-22 10:11:58
求高手帮忙,我写了个用户登录,前后用Extjs4.2写的表单,后台处理时,给Extjs返回一个用户是否存在的信息,但就是无法获得action中返回的信息,求大侠们告诉我到底要怎么写才可以获得action中返回的信息。

总是给我返回一个Ext.Error: You're trying to decode an invalid JSON String: 的错误。原因在那里我查了半天也不知道在哪儿,从网上看,似乎都是我这样的写法,求帮助。

Ext.define('SJXC.view.Login', {
extend : 'Ext.window.Window',
alias : 'widget.loginForm', // 别名
requires : ['Ext.form.*', 'SJXC.view.CheckCode'],
initComponent : function() {
var form = Ext.widget('form', {
border : false,
bodyPadding : 10,
fieldDefaults : {
labelAlign : 'left',
labelWidth : 55,
labelStyle : 'font-weight : bold'
},
defaults : {
margins : '0 0 10 0'
},
items : [{
xtype : 'textfield',
fieldLabel : '帐号',
blankText : '帐号不能为空',
name : 'user.account',
id : 'user.account',
allowBlank : false,
width : 240
}, {
xtype : 'textfield',
fieldLabel : '密码',
blankText : '密码不能为空',
allowBlank : false,
id : 'user.password',
name : 'user.password',
width : 240,
inputType : 'password'
}],
buttons : [{
text : '登录',
handler : function() {
if (form.isValid()) {
form.submit({
clientValidation : true,
waitMsg : '请稍后',
//waitTitle : '正在验证登录...',
url : 'user_login.action',
success : function(form, action) {
//Ext.Msg.alert("",action.result.msg);
},
failure : function(form, action) {
Ext.Msg.alert("ERROR",action.result.msg);
}
});
}
}
}]
});

Ext.apply(this,{
height: 160,
width: 280,
title: '用户登陆',
closeAction: 'hide',
closable : false,
iconCls: 'login',
layout: 'fit',
modal : true,
plain : true,
resizable: false,
items:form
});
this.callParent(arguments);
}

});

action中我是这样写的:
public String login() throws Exception{
User loginUser = userService.findByNameAndByPassword(user.getAccount(), user.getPassword());
if(loginUser == null){
System.out.println("用户不存在");
response.getWriter().write("{success:false, msg:'用户不存在'}");
return "loginUI";
} else {
ActionContext.getContext().put("user", user);
return "success";
}
}
...全文
305 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
hellocdkjq 2015-01-07
  • 打赏
  • 举报
回复
重置一下你的浏览器就对了
wxl1214471 2013-02-22
  • 打赏
  • 举报
回复
引用 1 楼 road_16 的回复:
response.setContentType("text/javascript;charset=UTF-8"); //在你的方法里边加入这一句 PrintWriter out = response.getWriter(); out.print("{success:false,msg:'"+msg+"'}") ; //这里是print,而你写的是write,你改下试……
我刚试了下,还是没有成功,不能获得action的返回值,进度条一直在走,
road_16 2013-02-22
  • 打赏
  • 举报
回复
response.setContentType("text/javascript;charset=UTF-8"); //在你的方法里边加入这一句 PrintWriter out = response.getWriter(); out.print("{success:false,msg:'"+msg+"'}") ; //这里是print,而你写的是write,你改下试试
菜牛 2013-02-22
  • 打赏
  • 举报
回复
你又没返回JSON

87,997

社区成员

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

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