【问题标题】:sending textfield data to servlet in ExtJS在 ExtJS 中将文本字段数据发送到 servlet
【发布时间】:2012-12-14 07:59:34
【问题描述】:

我想将文本字段数据发送到 servlet 页面。我不知道过程。我给出了文本框的代码和下面的按钮。

Ext.onReady(function(){
var movie_form = new Ext.FormPanel({
    renderTo: document.body,
    frame: true,
    title: 'Personal Information Form',
    width: 250,
    items: [{
        xtype: 'textfield',
        fieldLabel: 'Firstname',
        name: 'firstname',
        allowBlank: false
    },{
        xtype:'button',
        text:'save'    
    }]
});

});

这是一个文本框和一个按钮的代码。当我单击按钮时,该字段的数据将转到一个 servlet 页面。但我不能那样做。请任何人帮助我。 servlet 页面的名称是 url_servlet

【问题讨论】:

    标签: javascript servlets extjs extjs4.1


    【解决方案1】:

    要在后端处理数据,请查看@The Suresh Atta 的回答。

    我在您的代码中发现了一些勘误:

    1) 使用 Ext.create 函数构造一个 Ext 组件。
    2) 使用 Ext.getBody() 获取文档正文。
    3)将您的字段放在项目配置中,并将按钮放在按钮配置中(并不总是最佳实践)。

    Ext.create('Ext.form.Panel', {
        frame: true,
        title: 'Personal Information Form',
        width: 250,
        url: 'url_servlet',// The form will submit an AJAX request to this URL when submitted
        items: [{
            xtype: 'textfield',
            fieldLabel: 'Firstname',
            name: 'firstname',
            allowBlank: false
        }],
        buttons: [{
            text: 'Save',
            handler: function() {
                var form = this.up('form').getForm();
                if (form.isValid()) {
                    form.submit({
                        success: function(form, action) {
                           Console.log('Success', action.result.msg);
                        },
                        failure: function(form, action) {
                           Console.log('Failed', action.result.msg);
                        }
                    });
                }
            }
        }],
        renderTo: Ext.getBody()
    });
    

    希望对你有所帮助;)

    【讨论】:

      【解决方案2】:

      在您的服务方法中(获取或发布)

      您可以通过属性“名称”获取数据字段值。

        String firstname = reg.getParameter("firstname");
      

      【讨论】:

        猜你喜欢
        • 2018-08-21
        • 2020-07-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多