0
我想從控制器發送JSON對象到我的視圖,但無法發送它。 請幫我一把!從控制器傳遞JSON對象到視圖(jsp)
我使用以下代碼
public class SystemController extends AbstractController{
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
ModelAndView mav = new ModelAndView("SystemInfo", "System", "S");
response.setContentType("application/json;charset=UTF-8");
response.setHeader("Cache-Control", "no-cache");
JSONObject jsonResult = new JSONObject();
jsonResult.put("JVMVendor", System.getProperty("java.vendor"));
jsonResult.put("JVMVersion", System.getProperty("java.version"));
jsonResult.put("JVMVendorURL", System.getProperty("java.vendor.url"));
jsonResult.put("OSName", System.getProperty("os.name"));
jsonResult.put("OSVersion", System.getProperty("os.version"));
jsonResult.put("OSArchitectire", System.getProperty("os.arch"));
response.getWriter().write(jsonResult.toString());
// response.getWriter().close();
return mav; // return modelandview object
}
}
並且在觀看側我使用
<script type="text/javascript">
Ext.onReady(function(response) {
//Ext.MessageBox.alert('Hello', 'The DOM is ready!');
var showExistingScreen = function() {
Ext.Ajax.request({
url : 'system.htm',
method : 'POST',
scope : this,
success: function (response) {
alert('1');
var existingValues = Ext.util.JSON.decode(response.responseText);
alert('2');
}
});
};
return showExistingScreen();
});
請幫助我! – user752233 2011-05-13 11:54:55