tags:

views:

374

answers:

2

Hi I have the followig code:

page1.jsp The ajax function called on click of button

function ajaxFunction()
{
var xmlHttp;
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
alert("Data loaded");
      }
    }
  xmlHttp.open("GET","page2.jsp",true);
  xmlHttp.send(null);
}

page2.jsp

<%@ page import="javax.jms.*" %>

<%!
private QPublisher qPublisher = null;
public class QPublisher {

        private  TopicPublisher publisher = null;
        private  TopicSession   session   = null;
        public void configPublisher(){
               TopicConnectionFactory factory = null;
               TopicConnection connection = null;
                try {
                        factory = new com.tibco.tibjms.TibjmsTopicConnectionFactory("tcp");
                        connection = factory.createTopicConnection("user","pwd");
                session = connection.createTopicSession(false,javax.jms.Session.AUTO_ACKNOWLEDGE);
                javax.jms.Topic topic = session.createTopic("topic1");
                publisher = session.createPublisher(topic);
                } 
        }

        public void publish(String msg)
        {

                        javax.jms.TextMessage message = session.createTextMessage();
                        message.setText(msg);
                        publisher.publish(message);
            }
}
public void jspInit(){
        qPublisher = new QPublisher();
        qPublisher.configPublisher();
}
%>

<%
qPublisher.publish("This is a test for TT");
%>

If I call page2.jsp without using ajax, i.e from page1.jsp using

<form action="page2.jsp">

the message is picked by the subsciber and displayed.

but not by making an ajax..

I have basic idea of ajax, so please guide what am i missing?

A: 

I know this isn't really an answer to your question, but if you're not too coupled to using strict JSP and JMS you may want to investigate frameworks that do the plumbing for you.

For example, this is a video of a presentation on How using Grails to build twitter in 40 minutes. The presentation is by Graeme Rocher [twitter] - CTO of G2One, now owned by Spring Source. In the presentation, Graeme creates a fully functional, AJAX enabled, searchable, secure, JMS based twitter clone.

I'm sure there are similar examples for other web frameworks.

Like someone once said - "Don't reinvent the wheel, unless you're really interested in learning alot of low-level detail about wheels"

Kevin Williams
A: 

Are you sure that the Ajax code successfully invokes the page2.jsp? To verify this, you could simply replace the JMS related code with something more simple, just a JSP command which shows "Hello World" in the client.

mjustin
yes you are correct .even i doubt that page2.jsp is called or not.. if you on can guide how can i call the page2.jsp if would be great help
harshit