Ich möchte die Kontaktliste aus meiner Datenbank drucken, aber meine JSP-Ansicht kann nicht gedruckt werden.JSP kann keine Liste vom Federcontroller drucken
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>
<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?
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. –
Ich habe bereits meinen Tippfehler und Web-XML geändert. immer noch Wert wie mein Screenshot – faridrakh
fügen Sie Ihre web.xml –