一个用户登陆后mdb收到消息然后判断监控页面是否打开如果是就刷新他请问怎么实现 不判断页面是否打开也行不懂什么意思!

解决方案 »

  1.   

    用户登录的时候登录模块向监控模块发送消息 后者收到消息后去主动刷新一个页面比如monitor.jsp贴上发送和接受的代码
    这个是父类提供一些发送端和接收端公共的属性以继承
    package com.lbsman.jms;import java.util.*;
    import javax.jms.*;
    import javax.naming.*;
    import com.lbsman.common.PropertyFile;public class JMSBase {
      private String QCFName;
      private String QueueName;
      protected Context ctx;
      protected QueueConnectionFactory QCF;
      protected QueueConnection QC;
      protected Queue queue;
      protected QueueSession QSession;  public JMSBase() {
        ctx = null;
        QCF = null;
        QC = null;
        queue = null;
        QSession = null;
        PropertyFile pFile = new PropertyFile();
        pFile.setPropFile("c:/webinfo/web.properties");
        QCFName = pFile.getProp("QFCName");
        QueueName = pFile.getProp("QueueName");
      }  protected Context getInitialContext() throws NamingException {
        if (ctx == null) {
          try {
            Properties p = new Properties();
            p.put(Context.INITIAL_CONTEXT_FACTORY,
                  "weblogic.jndi.WLInitialContextFactory");
            ctx = new InitialContext(p);
          }
          catch (NamingException ne) {
            System.err.println("** Unable to connect to the server");
            ne.printStackTrace();
            throw ne;
          }
        }
        return ctx;
      }  protected void prepare() throws NamingException,JMSException {
         ctx = getInitialContext();
         QCF = (QueueConnectionFactory)ctx.lookup(QCFName);
         queue = (Queue)ctx.lookup(QueueName);
         ctx.close();
         QC = QCF.createQueueConnection();
         QSession = QC.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
      }
    }发送部分:
    package com.lbsman.jms;import javax.jms.*;public class LBSQSender
        extends JMSBase {
      private QueueSender QSender;
      private TextMessage TMSG;
      private String MsgContent;  public LBSQSender() {
        super();
        QSender = null;
        TMSG = null;
        MsgContent = "";
      }  public String getMsg() {
        return MsgContent;
      }  public void send(String msgCon) throws JMSException {
        MsgContent = msgCon;
        QSender = QSession.createSender(queue);
        TMSG = QSession.createTextMessage(MsgContent);
        QSender.send(TMSG);
      }  public static void main(String[] args) {
        LBSQSender Sender = new LBSQSender();
        try {
          Sender.prepare();
          Sender.send("hello");
        }
        catch (Exception e) {
          e.printStackTrace();
        }  }}
    接收程序
    package com.lbsman.jms;import javax.jms.*;
    import javax.servlet.http.HttpServletResponse;
    import com.lbsman.database.Database;
    import com.lbsman.common.InputCheck;public class LBSQReceiver
        extends JMSBase
        implements MessageListener {
      private QueueReceiver QReceiver;
      private HttpServletResponse response;  public LBSQReceiver(HttpServletResponse resp) {
        super();
        QReceiver = null;
        response = resp;
      }
      
      public LBSQReceiver() {
        super();
        QReceiver = null;
        response = null;
      }  private void receive() throws JMSException {
        QReceiver = QSession.createReceiver(queue);
        QReceiver.setMessageListener(this);
        QC.start();
      }  public void onMessage(Message message) {
        String msgText = "";
        String sqlStr = "";
        int usrid = 0;
        InputCheck check = new InputCheck();
        try {
          msgText = ( (TextMessage) message).getText();
          System.out.println(msgText);
        }
        catch (JMSException e) {
          e.printStackTrace();
        }
        if (check.isNum(msgText)) {
          try {
            usrid = Integer.parseInt(msgText);
          }
          catch (Exception e) {
            e.printStackTrace();
            System.exit(0);
          }
          try{
            response.sendRedirect("http://localhost:8080/");
          }
          catch(Exception e){
          e.printStackTrace();
         }
        }
      }  public static void main(String[] args) {
        LBSQReceiver Receiver = new LBSQReceiver();
        try {
          Receiver.prepare();
          Receiver.receive();
        }
        catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
    LBSQReceiver接收到消息后在onMessage(Message message)
    怎么样去刷新一个指定的页面比如说刷新http://localhost/myjob/monitor.jsp
      

  2.   

    http的连接是无状态的,文件传输完了连接就断开了,好像不行吧。可以用APPLET试试啊。
      

  3.   

    后者收到消息后可以改变你要记录的数据,然后将monitor.jsp设为定事刷新,不知道满不满足你的要求!
      

  4.   

    靠想来想去除了用applet没有别的办法一个javabean或者servlet的生存期有多长。我是指在javabean里的方法被调用后或者servlet的service方法别调用后他的实例就销毁了吗
      

  5.   

    wafer_w(流浪的风) 如过我定时刷页面那还用jms干什么