public void doGet(HttpServletRequest request, HttpServletResponse response)
            
throws ServletException, IOException {

        
//初始化參數
            Context ctx=null;
            QueueSender queueSender
=null;
            QueueSession queueSession
=null;
            QueueConnection queueConn
=null;
            
try {
                
//獲得上下文
                ctx = new InitialContext();
                
//獲得QueueConnectionFactory對象
                QueueConnectionFactory qcfact=(QueueConnectionFactory)ctx.lookup("ConnectionFactory");
                
//獲得Queue對象
                Queue queue=(Queue)ctx.lookup("queue/myQueue");
                
                
try {
                    
//獲得QueueConnection對象  由QueueConnectionFactory生成
                    queueConn = qcfact.createQueueConnection();
                    
//獲得queueSession對象  由QueueConnection對象生成
                    queueSession=queueConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
                    
//獲得QueueSender對象 由queueSession對象生成
                    queueSender=queueSession.createSender(queue);
                    
//生產TextMessage 并且把TextMessage對象加入到queueSession中
                    TextMessage textMessage=queueSession.createTextMessage();
                    textMessage.setText(
"this is default message..");
                    
//發送
                    queueSender.send(textMessage);
                    
                } 
catch (JMSException e) {
                    e.printStackTrace();
                }
            } 
catch (NamingException e) {
                e.printStackTrace();
            }
finally{
                
//判斷是否為空
                if(queueSender!=null&&queueSession!=null&&queueConn!=null){
                    
try {
                        
//管理所有連接
                        queueSender.close();
                        queueSession.close();
                        queueConn.close();
                    } 
catch (JMSException e) {
                        
// TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    
                }
            }
            
        
    }

    
/**
     * The doPost method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to post.
     * 
     * 
@param request the request send by the client to the server
     * 
@param response the response send by the server to the client
     * 
@throws ServletException if an error occurred
     * 
@throws IOException if an error occurred
     
*/
    
public void doPost(HttpServletRequest request, HttpServletResponse response)
            
throws ServletException, IOException {

        
this.doGet(request, response);
    }


柴油發電機
發電機
柴油機
柴油發電機
13636374743(上海)
13291526067(嘉興)