/** @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response) */
 protected void service(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   try {
     JsonList notices = new JsonList();
     for (Notice n : Notice.getNotices()) {
       JsonMap notice = new JsonMap();
       notice.put("nID", new JsonVal<Integer>(n.id));
       notice.put("title", new JsonVal<String>(n.getTitle()));
       notice.put("href", new JsonVal<String>(n.getHref()));
       notices.add(notice);
     }
     response.setCharacterEncoding("UTF-8");
     response.getWriter().print((new JsonMap("notices", notices)).toJsonStr());
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Esempio n. 2
0
 /** @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response) */
 protected void service(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   PrintWriter output = response.getWriter();
   JsonMap json = new JsonMap();
   json.put("name", new JsonVal<String>("MaoZili"));
   json.put("sex", new JsonVal<String>("Man"));
   json.put("age", new JsonVal<Integer>(20));
   JsonMap course[] = new JsonMap[3];
   course[0] = new JsonMap();
   course[0].put("name", new JsonVal<String>("JavaEE1"));
   course[0].put("time", new JsonVal<String>("Thur. 7,8"));
   course[0].put("place", new JsonVal<String>("Building Jishi, Room 530"));
   course[1] = new JsonMap();
   course[1].put("name", new JsonVal<String>("JavaEE2"));
   course[1].put("time", new JsonVal<String>("Thur. 7,8"));
   course[1].put("place", new JsonVal<String>("Building Jishi, Room 530"));
   course[2] = new JsonMap();
   course[2].put("name", new JsonVal<String>("JavaEE3"));
   course[2].put("time", new JsonVal<String>("Thur. 7,8"));
   course[2].put("place", new JsonVal<String>("Building Jishi, Room 530"));
   json.put("courses", new JsonList(course));
   output.print(json.toJsonStr());
 }