简体   繁体   English

Java中同一Web应用程序的两个会话之间的通信

[英]Communication between two sessions of same web application in java

I have a problem like two clients should be accessing my web application. 我有一个问题,例如两个客户端应该访问我的Web应用程序。 My first question is how can i know that two clients exist. 我的第一个问题是我怎么知道有两个客户。

If two clients exist i should have a communication as mentioned below. 如果有两个客户,我应该进行如下沟通。

Client1 should write once client1 writes then client2 should read it and will respond once client2 writes then client1 should read it and will respond in this pattern my communication should happen. 客户端1应该在客户端1写入之后进行写操作,然后客户端2应该对其进行读取,并且将在客户端2进行写入之后进行响应,然后客户端1应该对其进行读取,并且将以这种方式响应。

Any help will be appreciated...Thanks in advance 任何帮助将不胜感激...谢谢

Create an HttpSessionListener which will maintain a set of active sessions. 创建一个HttpSessionListener,它将维护一组活动会话。 When a servlet gets a request from client1 save request body in a client1 session attribute then look for client2 session in active session set, if found take body (previous client2 request) from there and send it as a response to client1. 当servlet从client1的请求中获取请求时,将请求主体保存在client1会话属性中,然后在活动会话集中查找client2会话(如果找到)从那里获取主体(先前的client2请求),并将其作为响应发送给client1。

我认为您正在寻找jsr 356.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM