标签不起作用...... Jsp没有打印任何东西......我可以在Eclipse中调试jsp页面吗? 查看
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<ul>
<c:forEach items="${listOfMyFriends}" var="friend">
<c:out value="${friend}"></c:out>
</c:forEach>
</ul>
</body>
</html>
控制器在MyController.java中
@Controller
public class MyController {
@RequestMapping(value="/my")
public String getMyHomePage(Model model) {
LinkedList<String> listOfMyFriends = new LinkedList<String>();
listOfMyFriends.add("friend1");
listOfMyFriends.add("friend2");
listOfMyFriends.add("friend3");
listOfMyFriends.add("friend4");
model.addAllAttributes(listOfMyFriends);
return "my";
}
}
答案 0 :(得分:5)
使用
替换return
之前的行
model.addAttribute("listOfMyFriends", listOfMyFriends);
当您执行model.addAllAttributes(listOfMyFriends);
It Copies all attributes in the supplied Collection into this Map, using attribute name generation for each element.
使用以下方法生成属性名称:Conventions.getVariableName()
因此,如果您不确定generated attribute name
的内容,请使用
model.addAttribute("listOfMyFriends", listOfMyFriends);
这样您就可以使用密钥"listOfMyFriends"
答案 1 :(得分:2)
将listOfMyFriends添加到Model中,如下所示:
model.addObject("listOfMyFriends ", listOfMyFriends );