title: HTTP Status 500 - java.lang.NullPointerException Servlet + jsp
body: <p>So here is the thing. I try to display some list of messages on main page of the web-site by using jsp. But when the tomcat server starts, I'm watching only on this error "HTTP Status 500 - java.lang.NullPointerException" that points to the line "for (Message message : messageList)"</p>
  
  <p>Here is the code of servlet:</p>
  
  <pre><code>public class MainPageServlet extends HttpServlet {
  
  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      MessageManager manager = new MessageManager();
      List&lt;Message&gt; messageList = manager.getMessages();
  
      request.setAttribute("messages", messageList);
  
      request.getRequestDispatcher("/main-page.jsp").include(request, response); } }
  </code></pre>
  
  <p>And here is a part of jsp:</p>
  
  <pre><code>&lt;%
  List&lt;Message&gt; messageList = (List&lt;Message&gt;) request.getAttribute("messages");
  for (Message message : messageList) {
  %&gt;
  &lt;div class="row" style="margin-top: 15px"&gt;
  &lt;div class="col-md-4 col-md-offset-4"&gt;
      &lt;div class="panel panel-primary"&gt;
          &lt;div class="panel-heading"&gt;
              &lt;h3 class="panel-title"&gt;
                  &lt;%= message.getLogin()%&gt;
              &lt;/h3&gt;
          &lt;/div&gt;
          &lt;div class="panel-body"&gt;
              &lt;%= message.getMessage() %&gt;
          &lt;/div&gt;
          &lt;div class="panel-footer"&gt;
              Posted at: &lt;%= message.getDate() %&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;%
  }
  %&gt;
  </code></pre>
  
  <p>I've tested on result of getting messageList and it's 100% ok. So where is the bug?
  Thnx in advance for helping!</p>