2014-11-24 75 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(); 
相关问题