• [extjs] ExtJs4.2 Form 表单提交


    基本代码:

    <script>

    Ext.onReady(function(){ Ext.create('Ext.form.Panel', { title: '登录', bodyPadding: 5, 350, // 将会通过 AJAX 请求提交到此URL url: '${pageContext.request.contextPath}/back/login.do', // 表单域 Fields 将被竖直排列, 占满整个宽度 frame: true, layout:'auto', // The fields defaultType: 'textfield', items: [{ fieldLabel: '用户名', name: 'name', allowBlank: false, blankText:'用户名不能为空' },{ fieldLabel: '密码', inputType:'password', name: 'pwd', allowBlank: false, blankText:'密码不能为空' },{ fieldLabel: '用户类型', name:'type', allowBlank: false, hidden:true, //隐藏组件 默认false value:1//表单默认值 } ], // 重置 和 保存 按钮. buttons: [{ text: '重置', handler: function() { this.up('form').getForm().reset(); } }, { text: '保存', formBind: true, //only enabled once the form is valid disabled: true, handler: function() { var form = this.up('form').getForm(); if (form.isValid()) { form.submit({ success: function(form, action) { Ext.Msg.alert('提示信息', action.result.restMsg); }, failure: function(form, action) { Ext.Msg.alert('提示信息', action.result.restMsg); } }); } } }], renderTo: Ext.getBody() }); }); </script>

      没有添加字段校验,验证码,密码加密等,只是纯粹的登录功能的实现,具体细节暂时忽略!

    login.do 对应的程序:

        /**
         * 登录
         * 
         * @return
         */
        @RequestMapping("/login")
        @ResponseBody
        public void login(@RequestParam String name,@RequestParam String pwd,@RequestParam int type,Writer writer) {
            String valMsg ="";
            try {
                User user = new User();
                user.setUname(name);
                user.setPwd(pwd);
                user.setUtype(type);
                User getUser = userService.queryUser(user);
                if(getUser!=null){
                    valMsg=showResultMsg(true, "登录成功");
                    //跳转到首页
                }else {
                    valMsg=showResultMsg(false, "用户不存在!");
                }
            } catch (Exception e) {
                e.printStackTrace();
                valMsg=showResultMsg(true, "登录失败");
            }finally {
                try {
                    writer.write(valMsg);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    返回的结果:

    {"result":true,"restMsg":"登录成功!"}
  • 相关阅读:
    Android学习笔记ActionView
    Android学习笔记添加ActionItem
    Android学习笔记显示和隐藏ActionBar
    Android学习笔记上下文菜单
    Android学习笔记菜单资源文件
    Android学习笔记样式资源文件
    Android学习笔记主题(Theme)资源文件
    Android学习笔记StateListDrawable文件
    Android学习笔记.9.png格式图片
    笔记本外接显示器设置全屏壁纸
  • 原文地址:https://www.cnblogs.com/lonelywolfmoutain/p/5084977.html
Copyright © 2020-2023  润新知