日期:2014-05-16 浏览次数:20353 次
var frm; Ext.onReady(function(){ var form1 = new Ext.FormPanel({ frame : true, width : 300, id : "frm", layout : "form", title : "添加个人信息", labelWidth : 70, labelAlign : "left", renderTo : "form1", items : [{ xtype : "textfield", fieldLabel : "用户名", name : "username", allowBlank : false, blankText : "不能为空!请正确填写!", anchor : "90%" },{ xtype : "textfield", fieldLabel : "昵称", name : "smallname", anchor : "90%" },{ xtype : "datefield", fieldLabel : "注册日期", name : "regdate", anchor : "90%" }], buttons : [{ text : "提交", handler : submit },{ text : "加载", handler : load },{ text : "取消", handler : reset }] }) frm = Ext.getCmp("frm"); //这两句话的意思是:校验 Ext.QuickTips.init(); Ext.form.Field.prototype.msgTarget = 'side'; }) /**submit**/ function submit() { if (!frm.getForm().isValid())return; frm.getForm().submit({ waitMsg : "正在提交数据……", waitTitle : "提示", url : "http://localhost:8080/ExtJsApp/formServlet", method : "post", success : function(form, action) { Ext.Msg.alert("提示","保存成功!"); }, failure : function(formm, action) { Ext.Msg.alert("提示","保存失败:" + action.result.errors.info); } }); } /**load**/ function load() { frm.getForm().load({ waitMsg : "正在加载数据……", waitTitle : "提示", url : "http://localhost:8080/ExtJsApp/formServlet", method : "get", success : function (form, action) { Ext.Msg.alert("提示","加载成功!"); } }) } /**reset**/ function reset() { frm.getForm().reset(); }
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/json; charset=utf-8"); String username = request.getParameter("username"); String smallname = request.getParameter("smallname"); if (username.equalsIgnoreCase("admin") && smallname.equalsIgnoreCase("ad")) { response.getWriter().print("{success:true,errors:{}}"); } else { response.getWriter().print("{success:false,errors:{info:'出错了!'}}"); } }