1. #1
    Sencha User
    Join Date
    Jul 2011
    Posts
    4
    Vote Rating
    0
    jGofio is on a distinguished road

      0  

    Default Problems retrieving data from JSP / Servlet

    Problems retrieving data from JSP / Servlet


    Hi

    I have a very simple application which should display a list of items retrieved from a JSP but I'm getting the following error:

    'Ext.data.JsonReader.getResponseData: Unable to parse JSON returned by Server.'


    The JSP file (test.jsp)
    --------------------


    Code:
    <%@ page language="java" pageEncoding="UTF-8"%>
    <%
      response.setContentType("application/json");  
      
      String result = "[{num: 100}]";
      
      response.getWriter().print(result);
      response.getWriter().flush();
    %>

    The js file
    --------------------


    Code:
    Ext.regModel('myModel', {
     fields: [ { name: 'num', type: 'int' }]
    });
    
    var myStore = new Ext.data.Store({
        
        model: 'myModel',
        autoLoad: true,
        storeId: 'myStore',
        
        proxy: {
    
            type: 'ajax',
            url: 'test.jsp',        
            reader: {type: 'json'}
        }
    });
    
    var App = new Ext.Application({
     
     name : 'MyApp',
     useLoadMask : true,
     launch : function () {
      
       MyApp.views.itemList = new Ext.List({
       id: 'itemList',
       store: 'myStore',
       itemTpl: '<div>{num}</div>',   
      });
       
      MyApp.views.itemListContainer = new Ext.Panel({
       
       id : 'itemListContainer',
       layout : 'fit',   
       items: [MyApp.views.itemList]
       });
         
      MyApp.views.viewport = new Ext.Panel({
       
       fullscreen : true,
       layout : 'card',
       cardAnimation : 'slide',
       items: [MyApp.views.itemListContainer]
       });
      }  
     });



    Any help is appreciated.


    Thanks

  2. #2
    Sencha User
    Join Date
    Jul 2011
    Posts
    4
    Vote Rating
    0
    jGofio is on a distinguished road

      0  

    Default


    Hi All!

    finally I found the problems...

    First, I have to specify the root element for the reader.
    Second, in the json returned by the servlet, num shold be between double quotes (and also add the root).

    Thanks to everyone that has had a look to this post!

  3. #3
    Sencha User
    Join Date
    Sep 2011
    Location
    Chennai, Tamil Nadu
    Posts
    24
    Vote Rating
    0
    Jay Tanwar is on a distinguished road

      0  

    Default STILL not working.. :(

    STILL not working.. :(


    Hi jGofio,
    I m a newbie to sencha + servlet. I tried running your code with double quotes on num n root( I also added root at both places.). still I m getting the same error.

    'Ext.data.JsonReader.getResponseData: Unable to parse JSON returned by Server.'
    my code:

    first file json.jsp
    Code:
    <%  response.setContentType("application/json");  
      
      String result = "{\"root\"[{\"num\": 100}]}";
      
      response.getWriter().print(result);
      response.getWriter().flush();
    %>
    sencha file sencha.js
    Code:
    Ext.regModel('myModel', {
     fields: [ { name: 'num', type: 'int' }]
    });
    
    
    var myStore = new Ext.data.Store({
        
        model: 'myModel',
        autoLoad: true,
        storeId: 'myStore',
        
        proxy: {
    
    
            type: 'ajax',
            url: 'json.jsp',        
            reader: {type: 'json', root: 'root'}
        }
    });
    
    
    var App = new Ext.Application({
     
     name : 'MyApp',
     useLoadMask : true,
     launch : function () {
      
       MyApp.views.itemList = new Ext.List({
       id: 'itemList',
       store: 'myStore',
       itemTpl: '<div>{num}</div>'  
      });
       
      MyApp.views.itemListContainer = new Ext.Panel({
       
       id : 'itemListContainer',
       layout : 'fit',   
       items: [MyApp.views.itemList]
       });
         
      MyApp.views.viewport = new Ext.Panel({
       
       fullscreen : true,
       layout : 'card',
       cardAnimation : 'slide',
       items: [MyApp.views.itemListContainer]
       });
      }  
     });
    Thnx..

Thread Participants: 1

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..."