2012-01-31 72 views
0

我在檢索參數時遇到了一個問題,即使用Ext.Ajax.request傳遞給我的JAVA控制器類。如何在java控制器中從Ext.Ajax.request中獲取參數

我使用下面的代碼

Ext.Ajax.request({ 
      url : 'projecttask/GetprojectTasks.action', 
      method: 'POST', 
      jsonData: { 
       sampledata: record.data 
      }, 
      type: 'json', 
      scope: this, // add the scope as the controller 
      callback : function(options, success, response) { 
       console.log('RESPONSE FROM SERVER :'+response); 
      } 
      }); 

我的Java控制方法接收請求發送請求到我的控制器

@RequestMapping(value="/projecttask/GetprojectTasks.action") 
    public @ResponseBody Map<String, ? extends Object> getprojectTasks(HttpServletRequest request, 
      HttpServletResponse response,@RequestBody Project project) throws Exception { 
     try { 
      System.out.println("PROJECT ::"+project); 
      System.out.println("RPOJECT DATA ::"+request.getParameter("sampledata")); 
      Object data = request.getParameter("sampledata"); 
      Project prj = (Project) data; 
      System.out.println("CREATE TASK DATA IS ::"+prj.getProjectid());    
      return null;    
     }catch(Exception e) { 
      return getModelMapError("Error trying to create contact"); 
     } 
    } 

,但它給了我下面

org.codehaus.jackson.map.JsonMappingException: Unrecognized field "sampledata" (Class com.kintu.projectmgt.model.Project), not marked as ignorable 
提到的錯誤

所以我做錯了哪些不允許我的函數獲取sampledata作爲參數傳遞ameters。我怎樣才能得到我的參數傳遞值任何想法?

我的螢火蟲顯示sampledata包含所有值。請幫我找到問題並儘快解決。

我使用Ext JS 4.0.2a和JAVA作爲我的serverside技術。

+0

抱歉,我通過從我的Ajax請求中刪除了jsonData和type來解決我的錯誤。相反,我剛剛添加** params:{'id':record.get('id')} **並在服務器端,我得到的值與request.getParameter(「id」)** – 2012-01-31 12:02:58

回答

0

可以使用

String postParamsJSON = request.getReader().readLine(); 

得到POST數據。

相關問題