-
14 Feb 2011 4:33 AM #1
Servlet Will response JSON object and will read json object using sencha
Servlet Will response JSON object and will read json object using sencha
Hi,
I am new to Sencha touch , I am using this scripts in android sdk using phone gap frame work.
I have implemented servlet which will respond JSON object.
JSONServlet .java
package com.bms;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
/**
* Servlet implementation class JSONServlet
*/
public class JSONServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public JSONServlet() {
super();
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
JSONArray arr = new JSONArray();
JSONObject obj1 = new JSONObject();
JSONObject obj2 = new JSONObject();
JSONObject obj4 = new JSONObject();
JSONObject obj5 = new JSONObject();
JSONObject obj6 = new JSONObject();
obj1.put("text", "abc");
obj1.put("url", "abc.com");
obj1.put("leaf", true);
obj4.put("text", "klm");
obj4.put("url", "klm.com");
obj4.put("leaf", true);
obj5.put("text", "xyz");
obj5.put("url", "xyz.com");
obj5.put("leaf", true);
obj6.put("text", "pqr");
obj6.put("url", "pqr.com");
obj6.put("leaf", true);
arr.add(obj1);
arr.add(obj4);
arr.add(obj5);
arr.add(obj6);
obj2.put("items",arr);
out.println(obj2);
//out.println(obj3.toString());
}
}
and In sencha script, I am calling the servlet and try to display the servlet output (Json format)
Ext.setup({
onReady : function() {
var cStore = new Ext.data.Store({
autoLoad: true,
proxy: {
type: 'ajax',
url: 'http://localhost:7001/JSONServlet/JSONServlet',
reader: {
type: 'json',
root: 'items',
totalProperty: 'results'
}
}
,fields: ['text', 'url']
});
}
});
While executing the script i got below exception
02-14 17:39:05.553: ERROR/Web Console(320): TypeError: Result of expression 'records' [undefined] is not an object. at file:///android_asset/www/sencha-touch-debug.js:7209
I found one more thing , request is not hitting to the server
help me on this , how to get the data?
-
14 Apr 2011 11:59 PM #2
First,
your servlet should be just url: 'JSONServlet',
I think your response type should be response.setContentType("application/json");
I hope it helps
Thank you for reporting this bug. We will make it our priority to review this report.
Similar Threads
-
Problem in Gridpanel when there is single object in Json response.
By anshu_gupta in forum Ext 3.x: Help & DiscussionReplies: 2Last Post: 9 Feb 2011, 3:26 AM -
[OPEN-733] failureType undefined if JSON response does not contain errors object
By Daniel-Percy in forum Ext 3.x: BugsReplies: 0Last Post: 15 Mar 2010, 2:39 PM -
how to enclose JSON object in response to Form submit error
By angelflaree in forum Ext 2.x: Help & DiscussionReplies: 2Last Post: 22 Feb 2008, 10:47 AM


Reply With Quote