protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
logger.info(“TimetableServlet doGet”);
HttpSession session = request.getSession(true);
try
{
timetableList = getListFromSomeWhere …
JSONObject responcedata=new JSONObject();
net.sf.json.JSONArray cell=new net.sf.json.JSONArray();
net.sf.json.JSONArray cellarray=new net.sf.json.JSONArray();
net.sf.json.JSONObject cellobj=new net.sf.json.JSONObject();
responcedata.put(“page”, Long.parseLong(“1”));
Iterator itr = timetableList.iterator();
while(itr.hasNext()){
Timetable t = itr.next();
cellobj.put(“id”, t.getId());
cell.add(t.field0().toString());
cell.add( StringUtil.StringToTime( t.field1()));
cell.add( StringUtil.StringToTime( t.field2()));
cellobj.put(“cell”, cell);
cell.clear();
cellarray.add(cellobj);
}
responcedata.put(“rows”, cellarray);
response.setContentType(“applisation/json”);
PrintWriter out = response.getWriter();
out.print(responcedata);
out.flush();
}
catch(Exception e)
{
logger.error(“Error TimetableServlet goGet: ” + e.toString());
}
}
It's work for me.