六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 31|回复: 0

Extjs+Struts2 Ajax 方式提交数据

[复制链接]

升级  31.33%

25

主题

25

主题

25

主题

秀才

Rank: 2

积分
97
 楼主| 发表于 2013-1-23 01:23:52 | 显示全部楼层 |阅读模式
前台Ext 代码
 
artist: {            xtype: 'panel',             title:'登录',              width:350,              id:'login-panel',              items:[{                  xtype:'form',                  id:'artist-form',                  defaultType:'textfield',                  bodyStyle : 'padding:5px',                  method:'POST',                  defaults:{                      anchor:'95%',                  },                  items:[{                      id:'loginName',                      name:'loginName',                      fieldLabel:'用户名',                   },{                      id:'password',                      name:'password',                      fieldLabel:'密码',                  }]             }],                        buttons: [{                text: 'Save',                handler: function(){                        var loginForm = Ext.getCmp('login-form').form;             loginForm.doAction('submit', {                      url:'login.action',                      method:'POST',                                            waitMsg:'正在登陆...',                      timeout:10000,//10秒超时,                      //params:loginForm.getValues(),                    success:function(form, action){              alert('登陆成功'+action.result)                        var isSuc = action.result.success;                        if(isSuc) {                              //提示用户登陆成功                              Ext.Msg.alert('消息', '登陆成功..');                          }                                                             },                      failure:function(form, action){                          alert('登陆失败');                      }                  });                  }            }    }; 
struts.xml
 
<package name="login" extends="json-default">        <action name="login" class="com.junjun.television.web.LoginAction">            <result type="json" />         </action>            </package> LoginAction.java
 
public String execute() {Watch watch = new Watch();watch.setNum(1);watch.setOnLine("asdfasdf");JSONObject jo = JSONObject.fromObject(watch);String jsonStr = jo.toString();System.out.println(jsonStr);try {// 返回成功标识response.getWriter().println("{success:true}");response.getWriter().println("{watch:"+jsonStr+"}");response.getWriter().flush();} catch (IOException e) {e.printStackTrace();} finally {try {response.getWriter().close();} catch (IOException e) {e.printStackTrace();}}return null;} java转json格式需要的jar包如下
   commons-beanutils.jar
   commons-collections-3.2.jar
   commons-lang-2.3.jar
   commons-logging.jar
   ezmorph-1.0.6.jar
   json-lib-2.4-jdk15.jar

 
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表