ext js グリッドに配置するために、ajax リクエストでサーブレットから返された json 配列を取得するにはどうすればよいですか? 注: 私のアプリケーションは常に空のグリッドを返します! これは私のajaxリクエストです:
Ext.Ajax.request({
url: 'src/AccessServlet.java',
method:'POST',
success: function ( result, request ) {
Ext.MessageBox.alert('Success', 'Data return from the server: '+ result.responseText);
myData =Ext.util.JSON.decode(result.responseText);
console.log(myData);
store.loadData(myData);
},
failure: function ( result, request) {
Ext.MessageBox.alert('Failed', result.responseText);
}
});
var store = new Ext.data.ArrayStore({
fields: [{name: 'name'},
{name: 'id'},]
});
var grid = new Ext.grid.GridPanel({
store: store,
columns: [ {header : 'Name',
width : 60},
{ header : 'id',
width : 60},],
height: 200});
grid.render('grid');
});
これは私のサーブレットです:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType("application/json");
System.out.println("Right!!You are in servlet now !!!!! ");
PrintWriter out = response.getWriter();
// Output stream to STDOUT
JSONObject myObject = new JSONObject();
myObject.put("name","xx");
myObject.put("id","123");
System.out.println(myObject);
JSONObject myRecord = new JSONObject();
myRecord.put("name","yy");
myRecord.put("id","12");
System.out.println(myRecord);
JSONArray myRecords = new JSONArray();
myRecords.add(myObject);
myRecords.add(myRecord);
System.out.println(myRecords);
}
私の web.xml ファイル:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web- app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>ajaxWithServlet</display-name>
<welcome-file-list>
<welcome-file>ajax.html</welcome-file>
</welcome-file-list>
<servlet>
<description></description>
<display-name>AccessServlet</display-name>
<servlet-name>AccessServlet</servlet-name>
<servlet-class>AccessServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>AccessServlet</servlet-name>
<url-pattern>/AccessServlet</url-pattern>
</servlet-mapping>
</web-app>
お願い助けて!