当前位置: 代码迷 >> 综合 >> 关于ExtJs4提交数据到jsp页面,返回正确的json显示例子。及error:You're trying to decode an invalid JSON String...解决方法
  详细解决方案

关于ExtJs4提交数据到jsp页面,返回正确的json显示例子。及error:You're trying to decode an invalid JSON String...解决方法

热度:39   发布时间:2024-01-17 21:19:21.0

json提交信息到jsp页面中处理,返回json数据到前台显示例子:

main.js

Ext.onReady(function(){var formPanel = Ext.create('Ext.form.Panel', {title: '输入项',renderTo: Ext.getBody(),//bobyPadding : 10,items: [{xtype: 'textfield',name: 'name',fieldLabel: '功能名称',border:'20',allowBlank: false  // 表单项非空},{xtype:'button',text:'保存',handler:function(){var basicForm = formPanel.getForm();//获取basicForm对象  if(basicForm.isValid()){basicForm.submit({ url : 'insertInfo.jsp',  method : 'post',  waitTitle : "提示",                 //等待的标题  waitMsg : '正在提交数据...',           //等待的信息  //params : {id: 'tom',foo: 'bar'},//传递参数  success:function(form,action){Ext.Msg.alert('Success', action.result.info);},failure : function(form,action){  }})}//如果客户端的验证通过则返回真  }}]});Ext.create('Ext.window.Window',{titile:'窗体',width: 400,modal: true,items: [formPanel   //填写表单面板],renderTo:Ext.getBody()}).show();
});

insertInfo.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><%String name = (String)request.getParameter("name");  //获取前台表单传递的参数System.out.println("name:"+name);String text = "{success:true,info:'"+name+"'}";  //拼写jsonresponse.getWriter().write(text);     //回传到前台%>
注意,其中上面的jsp文件不能有任何html代码,否则传递回去的json无法解析,会有报错信息: error:You're trying to decode an invalid JSON String...


  相关解决方案