私のJSPのビューに値リストを表示したいのですが、これはできません。Springを使用してJSPの値のリストを表示する
下記のコントローラクラスは、ModelAndView
マップにリストを追加するだけで、index.jsp
ページにリダイレクトされます。
EmployeeController
@Controller
public class EmployeeController {
@RequestMapping(value={"/employee"}, method = RequestMethod.GET)
public String listEmployee(){
System.out.println("Kontroler EmployeeController");
LinkedList<String> list = getList();
ModelAndView map = new ModelAndView("index");
map.addObject("lists", list);
return map.getViewName();
}
private LinkedList<String> getList(){
LinkedList<String> list = new LinkedList<>();
list.add("Item 1");
list.add("Item 2");
list.add("Item 3");
return list;
}
}
index.jspを
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Welcome to Spring Web MVC project</title>
</head>
<body>
<h1>Index page</h1>
<h1>${msg}</h1>
<a href="/MavenHello/employee">Zaměstnanci</a>
</body>
<c:if test="${not empty listEmployee}">
<ul>
<c:forEach var="listValue" items="${listEmployee}">
<li>${listValue}</li>
</c:forEach>
</ul>
</c:if>
たびに、私は"Zaměstnanci"
を打つので、私は、コントローラにアクセスすることができる午前、System.out.println("Kontroler EmployeeController")
プリント"Kontroler EmployeeController"
でTomcatにログ。ただし、index.jsp
ページは空白です。
助けてもらえますか?
あなたの投稿に表示されているようにすべてのファイルを更新しましたが、すべて正常に動作しています。ありがとうございます:) –