public void findUserJson() {
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
PrintWriter out = null;
try {
out = response.getWriter();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
out.write(this.findjson(userName));
out.flush();
out.close();
}
public String findjson(String username){
List<UserJson> userjsonList = findUserJsonByUser(username);
String jsonString = "[";
for (int i = 0; i < userjsonList.size(); i++) {
UserJson userjson = userjsonList.get(i);
if (i < (userjsonList.size())-1) {
jsonString = jsonString
+ "{\"id\":\""
+ userjson.getId()
+ "\",\"title\":\""
+ userjson.getTitle()
+ "\",\"start\":\""
+ BBSCSUtil.formatDateTime
(userjson.getStart(),
"yyyy-MM-dd") +
"\",\"content\":\""
+ userjson.getContent() + "\"},";
} else {
jsonString = jsonString
+ "{\"id\":\""
+ userjson.getId()
+ "\",\"title\":\""
+ userjson.getTitle()
+ "\",\"start\":\""
+ BBSCSUtil.formatDateTime
(userjson.getStart(),
"yyyy-MM-dd") +
"\",\"content\":\""
+ userjson.getContent() + "\"}";
}
}
jsonString = jsonString + "]";
return jsonString;
}