乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      WebSocket之獲取HttpSession

       liang1234_ 2020-02-07

      由于WebSocket與Http協議的不同,故在使用常用的HttpSession方面就存在了一些問題。通過google翻閱到了在onOpen方法下使用HttpSession的方法。

      新建一個GetHttpSessionConfigurator類并繼承Configurator類

      復制代碼
      package per.zww.web;
      
      import javax.servlet.http.HttpSession;
      import javax.websocket.HandshakeResponse;
      import javax.websocket.server.HandshakeRequest;
      import javax.websocket.server.ServerEndpointConfig;
      import javax.websocket.server.ServerEndpointConfig.Configurator;
      /*
       * 獲取HttpSession
       * 
       */
      
      public class GetHttpSessionConfigurator extends Configurator {
      
          @Override
          public void modifyHandshake(ServerEndpointConfig sec,
                  HandshakeRequest request, HandshakeResponse response) {
              // TODO Auto-generated method stub
              HttpSession httpSession=(HttpSession) request.getHttpSession();
              sec.getUserProperties().put(HttpSession.class.getName(),httpSession);
          }
          
      }
      復制代碼

      然后在@ServerEndpoint注解里面添加configurator屬性

      @ServerEndpoint(value="/socketTest",configurator=GetHttpSessionConfigurator.class)

      在onOpen方法里加入參數EndpointConfig config即可獲取HttpSession

        @OnOpen
          public void onOpen(Session session,EndpointConfig config) {
              HttpSession httpSession= (HttpSession) config.getUserProperties().get(HttpSession.class.getName());
              System.out.println( httpSession.getAttribute("name"));
              sessionMap.put(session.getId(), session);
          }

       

        本站是提供個人知識管理的網絡存儲空間,所有內容均由用戶發(fā)布,不代表本站觀點。請注意甄別內容中的聯系方式、誘導購買等信息,謹防詐騙。如發(fā)現有害或侵權內容,請點擊一鍵舉報。
        轉藏 分享 獻花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多