For websockets you have to use HTML5.
https://www.websocket.org/aboutwebsocket.html
You can use various methods to implement chat functionality if you want to use HTML4 like the asyc feature of servlet 3 for chat as in the following link
https://github.com/rstoyanchev/spring-mvc-chat
For HTML4, Web Sockets are not available. Generally used mechanisms are long polling and streaming. While for HTML5, full duplex communication channels can be established with Server using Web Sockets. Accessible using JavaScript interface in HTML5 compliant browsers.
HTML4 does not allow JavaScript to run in browser. JS runs in same thread as browser interface. HTML5 allows JavaScript to run in background. This is possible due to JS Web worker API in HTML5