Cap*_*ich 0 java eclipse jsp jstl spring-mvc
标签不起作用...... 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>
Run Code Online (Sandbox Code Playgroud)
控制器在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";
}
}
Run Code Online (Sandbox Code Playgroud)
前替换行return用
model.addAttribute("listOfMyFriends", listOfMyFriends);
Run Code Online (Sandbox Code Playgroud)
当你这样做的时候 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);
Run Code Online (Sandbox Code Playgroud)
这样您就可以使用密钥访问朋友列表 "listOfMyFriends"
| 归档时间: |
|
| 查看次数: |
260 次 |
| 最近记录: |