title: How to Subscribe to a ActiveMQ topic using its Ajax feature.
body: <p>I am using ActiveMQ as my JMS provider and JSP to build up a real-time web application. The web application should subscribe to a topic produced in some other applications. </p>
  
  <p>I have successfully deploy my we web application in Tomcat. Also, I have put all needed jar files in the lib directory. However, I still get an error, see the following error info from Google Chrome. Can someone tell me how to fix this problem. </p>
  
  <p><img src="https://i.stack.imgur.com/CvuVm.jpg" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/ajlQN.jpg" alt="enter image description here"></p>
  
  <p>My web.xml</p>
  
  <pre><code>     &lt;context-param&gt;
          &lt;param-name&gt;org.apache.activemq.brokerURL&lt;/param-name&gt;
          &lt;param-value&gt;vm://localhost&lt;/param-value&gt;
        &lt;/context-param&gt;
  
       &lt;servlet&gt;
            &lt;servlet-name&gt;AjaxServlet&lt;/servlet-name&gt;
            &lt;servlet-class&gt;org.apache.activemq.web.AjaxServlet&lt;/servlet-class&gt;
        &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
  
    &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;AjaxServlet&lt;/servlet-name&gt;
        &lt;url-pattern&gt;/amq/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  
    &lt;servlet&gt;
        &lt;servlet-name&gt;MessageServlet&lt;/servlet-name&gt;
        &lt;servlet-class&gt;org.apache.activemq.web.MessageServlet&lt;/servlet-class&gt;
    &lt;/servlet&gt;
  
    &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;MessageServlet&lt;/servlet-name&gt;
        &lt;url-pattern&gt;/message/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>My index.jsp</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;title&gt;Rainbow for Nurse Station&lt;/title&gt;
  
  &lt;script type="text/javascript" src="amq/amq.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  
  var amq = org.activemq.Amq;
  amq.init({ 
  uri: 'amq', 
  logging: true,
  timeout: 20
  });
  
  
  var myHandler =  
  {  
    rcvMessage: function(message)  
    {  
      document.writeln(message); 
    }  
  };  
  
  
  amq.addListener("test", "topic://RAINBOW_NURSECALL", myHandler.rcvMessage);
  
  &lt;/script&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
  
  None.
  
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>