将多个值从java传递给jsp

时间:2011-05-13 13:08:26

标签: spring-mvc

您好我正在尝试将参数从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();

});

1 个答案:

答案 0 :(得分:1)

这是一种做你的头衔要求的方式......

在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.
...