取决于初始化参数的含义。您可以执行以下操作:
@ServerEndpoint(value = "/websocket/{clientId}")public class Service { private volatile String clientId; @onOpen public void init(@PathParam("clientId") String clientId, Session session) throws IOException { this.clientId = clientId; }}然后,您必须使用以下URL访问端点:
ws://host/contextPath/websocket/[clientId]。
如果您使用查询参数,请参阅
Session#getQueryString()。



