斗士狗 2009-03-30 13:08 采纳率: 0%
浏览 66

使用ajax调用JMS

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?

  • 写回答

2条回答 默认 最新

  • weixin_33720078 2009-03-30 18:32
    关注

    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"

    评论

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题