js:
<script>
function show(name){
$.post("groupAction_getAllByGroup.action",{name:name}, function(data){
$(data.users).each(function(){
alert($(this).attr("username"));
});
});
}
</script>
后台action:
public String getAllByGroup() throws Exception {
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
response.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
JSONArray jsonArray = new JSONArray();
JSONObject jsonobj = new JSONObject();
String name = request.getParameter("name");
List<User> users = dao.getAllByGroup(name);
User us = new User();
us.setUser_name("names");
users.add(us);
for(User user : users){
jsonobj.put("username", user.getUser_name());
jsonArray.add(jsonobj);
}
jsonobj = JSONObject.fromObject(jsonArray);
out.print(jsonobj);
out.flush();
out.close();
return null;
}