First,I set attribute in servlet before websocket.
I'm sure the attribute is not null and print it on console.
session.setAttribute("user",request.getParameter("name"));
Then I establish websocket from HTML5 and get httpsession in modifyHandshake. But I get null.
public class GetHttpSessionConfigurator extends ServerEndpointConfig.Configurator
{
@Override
public void modifyHandshake(ServerEndpointConfig config,
HandshakeRequest request,
HandshakeResponse response)
{
HttpSession httpSession = (HttpSession)request.getHttpSession();
config.getUserProperties().put(HttpSession.class.getName(),httpSession);
System.out.println("username:"+httpSession.getAttribute("user"));
}
}
It print 'null' on console.
Why?