jsp页面无法识别来自servlet的列表

时间:2016-08-06 12:37:58

标签: java jsp servlets web-applications

我将在jsp页面上打印列表中的项目。列表中有一个项目。 Servlet代码:

@WebServlet("/BlogListServlet")
public class BlogListServlet extends HttpServlet{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Blog blog= (Blog) getServletContext().getAttribute("blog");
        Map<Integer, Post> posts= blog.getPosts();
        List<Post> list = new ArrayList<Post>(posts.values());
        req.setAttribute("posts",list);
        resp.sendRedirect("bloglist.jsp");        
    }
}

JSP:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page contentType="text/html" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>BlogPost</title>
  <link rel="stylesheet" type="text/css" href="css/blogpost.css"/>
</head>
<body>
<table>
  <c:forEach var="post" items="${posts}">
    <tr>
    <td>${post.name} - ${post.jaar}</td>
    <td>${post.specialisatie}</td>
    <td>${post.omschrijving}<br/><a href="${post.url}">${post.url}</a></td>
    </tr>
  </c:forEach>
</table>
</body>
</html>

导致浏览器:

  

$ {post.name} - $ {post.jaar} $ {post.specialisatie} $ {post.omschrijving}   $ {post.url}

0 个答案:

没有答案