0

I will print the items from a list on a jsp page. There is one item in the list. Servlet code:

@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>

result in the browser:

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

CSharp
  • 1
  • 2
  • Is JSTL works on this page ? I have the impression that it is a configuration problem and it's not specific to your list. `` doesn't seem to be interpreted. Try `` to check – davidxxx Aug 06 '16 at 12:47
  • Please copy and paste the result here, and include it as another code field. It is generally good practice to include all relevant information for your question on the stackoverflow site, rather than referencing other sites. This is to ensure that it is easy for people to answer your question. It is also important because if your image is removed from your external site others with the same issue as you in future will still benefit from this question. – silvergasp Aug 06 '16 at 12:58

0 Answers0