2012-05-08 24 views
0

我帶彈簧3.1和方法的工作應該返回由JSPX頁面所代表的觀點得到模型變量。在調試時,我看到名爲noteList的模型中的變量,我無法在頁面上打印或迭代此變量。不能在JSPX頁面

輸出爲${noteList}

下面是一些代碼:

@RequestMapping(value = "/", method = RequestMethod.GET) 
public ModelAndView rootPage(){ 
    List<Note> result = sessionFactory.openSession().createCriteria(Note.class).list(); 

    ModelAndView mv = new ModelAndView("index"); 
    mv.addObject(result); 
    return mv; 
} 

<?xml version="1.0" encoding="UTF-8" ?> 
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" 
    xmlns:c="http://java.sun.com/jsp/jstl/core" 
    xmlns:spring="http://www.springframework.org/tags" version="2.0"> 
    <jsp:directive.page language="java" 
     contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" /> 

    <![CDATA[<!DOCTYPE html>]]> 
    <html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
<title>Index page</title> 
</head> 
<body> 
    <c:out value="${noteList}"/> 
</body> 
    </html> 
</jsp:root> 

<beans:bean id="viewResolver" 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <beans:property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> 
     <beans:property name="prefix" value="/WEB-INF/views/" /> 
     <beans:property name="suffix" value=".jspx" /> 
    </beans:bean> 

回答

0

謝謝大家!我有一個答案。

的問題是在JSPX頁面

工作頁面包含在開始下面的代碼:

<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" 
    xmlns:c="http://java.sun.com/jsp/jstl/core" 
    xmlns:spring="http://www.springframework.org/tags" 
    xmlns:form="http://www.springframework.org/tags/form" version="2.0"> 

    <jsp:output doctype-root-element="html" omit-xml-declaration="true" 
     doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" 
     doctype-system="http://www.w3c.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" /> 
    <jsp:directive.page language="java" 
     contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" /> 

    <html> 
<head> 
..... 
1

由於noteList包含對象類型Note的列表,你可以嘗試訪問Note對象的屬性之一。假設你有一個Note屬性name,然後嘗試在你的JSP {node.name}