用extJs进行表单提交返回json对象
这个例子是用extJs表单提交和struts2结合的例子。
首先,要进行编写js文件,js中文件建立一个button按钮,然后单击的时候响应下面的事件,此处就省略对于button的编写。响应的函数如下
?
?function addProgramItem() {
??firstWindow.show(); // 显示窗口
?}
?//-------------添加费率的 -------------------------
?var firstWindow = new Ext.Window({
????title : '<span namespace="/" extends="json-default">
????? <action name="program_save" method="save">
???????????? <result name="success" type="json"></result>
??????? </action>
?</package>
?
?
返回sucess就对应这表单提交后执行extjs中成功的回调函数
?public String save() throws IOException
?{
??? ?programService.save(program);
?? ??HttpServletResponse response = ServletActionContext.getResponse();
??? ?PrintWriter out = response.getWriter();
??? ?out.println("{success:true,msg:'tariff_program addd success'}");
???? out.flush();
??? ?out.close();
??? ?return SUCCESS;
?}