2014-11-24 73 views
-1

我正在使用smack庫從我的android應用程序接收消息到服務器。 下面是我的代碼:如何從smack庫的packetlistener中調用java servlet的doGet方法?

 String username=this.GCM_SENDER_ID+"@gcm.googleapis.com"; 
    String password=this.GCM_SERVER_KEY; 

    config = new ConnectionConfiguration(GCM_SERVER, GCM_PORT); 
    config.setSecurityMode(SecurityMode.enabled); 
    config.setReconnectionAllowed(true); 
    config.setRosterLoadedAtLogin(false); 
    config.setSendPresence(false); 
    config.setSocketFactory(SSLSocketFactory.getDefault()); 
    config.setDebuggerEnabled(false); 

    connection=new XMPPTCPConnection(config); 
    connection.connect(); 

    connection.addConnectionListener(new AppConnectionListener()); 
    connection.addPacketListener(new AppPacketListener(),new PacketTypeFilter(Message.class)); 
    connection.addPacketInterceptor(new AppPacketInterceptor(), new PacketTypeFilter(Message.class)); 

    connection.login(username, password); 

現在,當有新郵件在服務器接收,AppPacketListener被調用。 我想要的是調用一個java servlet的doGet方法或發送一個get請求到其他jsp頁面。 我該怎麼做?有小費嗎?

回答

0

您可以使用URLConnection從您的java客戶端調用servlet。默認情況下,如果您調用servlet,將調用doGet方法(即​​)。

oracle tutorial

InputStream response = new URL("http://myhost.com/myservlet").openStream(); 
相關問題