title: ClassCastException with Tomcat and JSP
body: <p>I'm working on a website with Java Servlets and JSPs. I'm running it on tomcat. 
  One of my JSP's makes use of a custom class called Message. I set an arraylist messages in a servlet and then try to access it in my JSP, using request.getAttribute() 
  If I print the Messages to the console, it works. However, when I try to make use of them on my website I get an exception. </p>
  
  <pre><code>java.lang.ClassCastException: Message cannot be cast to classes.Message
  org.apache.jsp.html.Chatroom_jsp._jspService(Chatroom_jsp.java:137)
  org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:4 
  53)
  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
  org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  MessageServlet.doGet(MessageServlet.java:67)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
  org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  </code></pre>
  
  <p>Steps I have taken: put a page import on top of jsp, added the class to web-inf/classes and added the classes to catalina.properties. But still its not working.
  Any help would be greatly appreciated!</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"
   %&gt;
   &lt;%@page import="java.sql.DriverManager"%&gt;
  &lt;%@page import="java.sql.ResultSet"%&gt;
  &lt;%@page import="java.sql.Statement"%&gt;
  &lt;%@page import="java.sql.Connection"%&gt;
  &lt;%@page import="java.sql.Date"%&gt;
  &lt;%@page import="java.sql.SQLException"%&gt;
  &lt;%@page import="java.sql.PreparedStatement"%&gt;
  &lt;%@ page import="java.util.ArrayList"%&gt;
  &lt;%@ page import="java.util.Iterator"%&gt;
  &lt;%@ page import="java.util.List"%&gt;
  &lt;%@ page import="classes.Message"%&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;title&gt;Insert title here&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;h2&gt;Chat Messages&lt;/h2&gt;
  
  &lt;table&gt;
  &lt;!-- dynamically generate the messages here  --&gt;
  &lt;tr&gt;
      &lt;th&gt;user&lt;/th&gt;
      &lt;th&gt;message&lt;/th&gt;
      &lt;th&gt;time&lt;/th&gt;
  &lt;/tr&gt;
  
  &lt;%
  
      //set the messages into an arraylist
      ArrayList &lt;Message&gt; msgs = new ArrayList&lt;Message&gt;();
      msgs = (ArrayList) request.getAttribute("messages");
      //TEST OUTPUT, to check if we can access messages
      System.out.println("hi. this is the message");
      System.out.println(msgs.get(0));
      //Message mess = new Message();
      //mess.setMessage(msgs.get(0).getMessage());
      //mess.setTime(msgs.get(0).getTime());
      //mess.setUserId(msgs.get(0).getUserId());
      //mess.setFname(msgs.get(0).getFname());
  
      for(Message mess : msgs)
      {
          %&gt;
          &lt;td&gt;&lt;%=mess.getFname() %&gt;&lt;/td&gt;
          &lt;td&gt;&lt;%=mess.getMessage() %&gt;&lt;/td&gt;
          &lt;td&gt;&lt;%=mess.getTime() %&gt;&lt;/td&gt;
          &lt;%
      }
  
  %&gt;  
  
  
  &lt;/table&gt;
  
  
  &lt;form&gt;
  &lt;div class="container"&gt;
        &lt;input type="text" placeholder="Enter message here " name="userPost" required&gt;
        &lt;button onClick = 'myFunction(); return false' type="submit"&gt;Submit&lt;/button&gt;
      &lt;p id = "demo"&gt;&lt;/p&gt;
  
  &lt;/div&gt;
  &lt;/form&gt;
  &lt;script&gt;
  function myFunction() {
      document.getElementByID("demo").innerHTML = "Hello";
  }
  
  // Get the modal
  var model = document.getElementById('id01');
  
  &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>