package controller; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import net.sf.json.JSONObject; import org.springframework.web.servlet.ModelAndView; public abstract class JSONObjectAbstractController extends AbstractViewController { @Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { JSONObject jsonObject = handleAjaxRequestInternal(request, response); response.setContentType("text/Xml;charset=gbk"); PrintWriter out = null; try { out = response.getWriter(); out.println(jsonObject.toString()); } catch (IOException ex1) { ex1.printStackTrace(); } finally { out.close(); } return null; } protected abstract JSONObject handleAjaxRequestInternal( HttpServletRequest request, HttpServletResponse response) throws Exception; } package controller; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import net.sf.json.JSONObject; public class JsonController extends JSONObjectAbstractController { @Override protected JSONObject handleAjaxRequestInternal( HttpServletRequest request, HttpServletResponse response) throws Exception { JSONObject object = new JSONObject(); object.put("userInfoMap", "json-value"); return object; } }