S2SH、EXTJS、JSON整合后,EXTJS接收不到Struts2的Action传回的值,无语!
EXTJS
Ext.onReady(function(){ var f = new Ext.form.FormPanel({ //数据传送到服务器的配置 url: "/BackOS/login.action", method: "post",// baseParams: {extra: "中华人民共和国", id: 100}, title: "欢迎登陆", width: 300, autoHeight: true, bodyStyle: "padding: 6px", labelAlign: "right", defaultType: "textfield",//默认组件类型 frame: true, items: [ new Ext.form.TextField({ name: "teller.tellerno", allowBlank: false, //不允许为空 value: "000000", fieldLabel: "用户名" }),{ name: "teller.password", inputType: "password", value: "123456", fieldLabel: "密码", allowBlank: false //不允许为空 } ], buttons:[{ text: "确定", handler: function(){ var userName = f.getForm().findField("teller.tellerno").getValue(); var password = f.getForm().findField("teller.password").getValue();// Ext.Msg.alert("", "用户名:" + userName + "<br>密码:" + password); //提交表单 f.getForm().submit({ success: function(f, action){ Ext.Msg.alert("",action.responseText);// Ext.Msg.alert("成功", "恭喜,表单提交成功,服务器反馈的结果是:"); }, failure: function(){ Ext.Msg.alert("失败", "对不起,表单提交失败"); } }); } }, { text: "重置", handler: function(){ //f.getForm().reset(); var fields = f.getForm().items.items; for(var i = 0; i < fields.length; i ++){ fields[i].reset(); } } }] }); f.render("login");})
public String execute() throws Exception { HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("text/html;charset=utf-8"); if(itt.userLogin(teller)){ System.out.println("-------------1"); response.getWriter().println("{success:'true'}"); return SUCCESS; } else{// response.getWriter().println("{success:false,msg:'失败登陆'}"); return SUCCESS; } }
<package name="nothing" extends="json-default"> <default-action-ref name="login" /> <action name="login" class="loginAction"> <result type="json"></result> </action> </package>
tphonetell0_.workphone as workphone0_,
tphonetell0_.mobphone as mobphone0_,
tphonetell0_.zcomment as zcomment0_
from
scott.t_phone_teller tphonetell0_
where
tphonetell0_.tellerno=?
and tphonetell0_.password=?
22:52:04,000 DEBUG HibernateTemplate:389 - Eagerly flushing Hibernate session
22:52:04,000 DEBUG SessionFactoryUtils:789 - Closing Hibernate Session
-------------1
22:52:04,031 DEBUG JSONUtil:68 - [JSON]{"teller":{"bankno":null,"branchno":null,"mobphone":null,"netnodeno":null,"password":"123456","tellername":null,"tellerno":"000000","tellertype":null,"workphone":null,"zcomment":null}}
22:52:04,046 DEBUG I18nInterceptor:68 - after Locale=zh_CN
22:52:04,046 DEBUG I18nInterceptor:68 - intercept }
这里说明后台可以接收到前台的数据并验证成功,后台加【JSON】也不行。response.getWriter().println("[JSON]{success:'true'}");,前台还是一点反应没有,已经调了一天了,还是没调好,只好来这求助下,先谢谢诸位大侠!
[解决办法]
配置文件的问题吧 仔细查看配置正确没?
[解决办法]
response.getWriter().println("{success:'true'}");
return SUCCESS;
改为return null;试试