2011-05-13 145 views
0

您好,我正在嘗試將參數從java傳遞給jsp文件。但我沒有得到它 這裏是我的代碼:將多個值從java傳遞給jsp

protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { 
    ModelAndView mav = new ModelAndView("SystemInfo", "System", "S"); 

    request.setAttribute("JVMVendor", System.getProperty("java.vendor")); 
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()); 


    return mav;    // return modelandview object 
} 

,在我的JSP文件我使用:

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) {     
      var existingValues = Ext.util.JSON.decode(response.responseText);   
      } 
    }); 
}; 

return showExistingScreen(); 

});

+0

你是在說傳遞價值給你的jsp,還是通過ajax調用將JSON傳遞給頁面? – MicronXD 2011-05-13 13:17:19

回答

0

這裏是做什麼你的標題是要求的一種方式......

在java中

mav.addObject("ThingOne", "value of thing one."); 
mav.addObject("ThingTwo", "value of thing two."); 
在jsp

<%@ taglib uri='http://java.sun.com/jstl/core' prefix='c'%> 

... 

<c:out value="${ThingOne}"/><br /> 
<c:out value="${ThingOne}"/> 

... 

應該給你:

... 
value of thing one. 
value of thing two. 
...