2016-03-29 12 views
0

Ich möchte die Kontaktliste aus meiner Datenbank drucken, aber meine JSP-Ansicht kann nicht gedruckt werden.JSP kann keine Liste vom Federcontroller drucken

this is contact view

dies Controller

@RequestMapping(value="contact") 
public ModelAndView listContact(ModelAndView model) throws IOException{ 
    List<contactModel> listContact = contactDAO.listContact(); 
    model.addObject("listContact", listContact); 
    model.setViewName("contact"); 
    for(contactModel contact : listContact){ 
     System.out.println(contact.getCid()+", "+contact.getUid()+", "+contact.getName()); 
    } 
    return model; 
} 

dies

Ansicht Code
<%@page contentType="text/html" pageEncoding="UTF-8"%> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
    "http://www.w3.org/TR/html4/loose.dtd"> 
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 
<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
     <title>Contact Manager Home</title> 
    </head> 
    <body> 
     <div align="center"> 
      <h1>Contact List</h1> 
      <h3><a href="newContact">New Contact</a></h3> 
      <table border="1"> 
       <th>No</th> 
       <th>Name</th> 
       <th>Email</th> 
       <th>Address</th> 
       <th>Telephone</th> 
       <th>Action</th> 

       <c:forEach var="contact" items="${ListContact}" varStatus="status"> 
       <tr> 
        <td>${status.index + 1}</td> 
        <td>${contact.name}</td> 
        <td>${contact.email}</td> 
        <td>${contact.address}</td> 
        <td>${contact.phone}</td> 
        <td> 
         <a href="editContact?id=${contact.id}">Edit</a> 
         &nbsp;&nbsp;&nbsp;&nbsp; 
         <a href="deleteContact?id=${contact.id}">Delete</a> 
        </td>   
       </tr> 
       </c:forEach>     
      </table> 
     </div> 
    </body> 
</html> 

web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> 
    <display-name>Reminder and Address Book</display-name> 
    <context-param> 
     <param-name>contextClass</param-name> 
     <param-value> 
      org.springframework.web.context.support.AnnotationConfigWebApplicationContext 
     </param-value> 
    </context-param> 
    <listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 

    <servlet> 
     <servlet-name>SpringDispatcher</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <init-param> 
      <param-name>contextClass</param-name> 
      <param-value> 
       org.springframework.web.context.support.AnnotationConfigWebApplicationContext 
      </param-value> 
     </init-param> 
     <init-param> 
      <param-name>contextConfigLocation</param-name> 
      <param-value>com.hbj.raddb.config</param-value> 
     </init-param> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>SpringDispatcher</servlet-name> 
     <url-pattern>/</url-pattern> 
    </servlet-mapping> 
</web-app> 

Kontaktwert kann nur drucken in der Konsole, kann aber nicht auf Jsp-Ansicht drucken. Wo ist mein Fehler? Kann mir jemand mein Problem helfen?

+0

Zuerst haben Sie einen Tippfehler 'ListContact' ist nicht' listContact', den Sie dem Modell hinzufügen. Auch wenn EL nicht analysiert wird, haben Sie wahrscheinlich eine Zeile in Ihrer web.xml, die angibt, dass es sich um eine Version 2.3 statt neuer handelt. –

+0

Ich habe bereits meinen Tippfehler und Web-XML geändert. immer noch Wert wie mein Screenshot – faridrakh

+0

fügen Sie Ihre web.xml –

Antwort

2

Sie haben einen Tippfehler, Änderung:

<c:forEach var="contact" items="${ListContact}" varStatus="status"> 

zu:

<c:forEach var="contact" items="${listContact}" varStatus="status"> 
+0

immer noch nicht drucken – faridrakh

0

Sie werden diese Variablen mit <c:out> umgeben müssen. Beispiel:

<td><c:out value="${status.index + 1} /></td> 
+0

nichts zu ändern. immer noch wie mein Screenshot – faridrakh