我是ExtJS和Servlet的新手。
我使用ExtJS创建了一个包含2个字段的表单:
var panel = Ext.create('Ext.form.Panel',
{
title: 'Personnal Data',
bodyPainting: 5,
width: 350,
region:'center',
url: 'save_form.php',
items:
[{
xtype: 'textfield',
fieldLabel: 'First Name ',
name: 'firstName'
},
{
xtype: 'textfield',
fieldLabel: 'Last Name ',
name: 'lastName'
}],
buttons:
[{
text: 'Submit',
handler: function()
{
var formData = this.up('form').getForm();
}
}]
});
但我不知道如何通过单击按钮将两个字段的值传递给servlet。 如何在servlet中检索表单中输入的数据?
谢谢!
答案 0 :(得分:0)
默认情况下,ExtJS Forms将以“ajax”方式发送值,我相信它将是一个“帖子”。在您的servlet中(假设您要在doPost(或doGet)方法中发布到web.xml文件中定义的servlet),请在方法中使用“request”变量并执行
request.getParameter("firstName")
和
request.getParameter("lastName")
Link to HttpServlet Definition (is the same for just about every java container).
编辑:
在您的处理程序中,您需要添加:
formData.submit();