Thank you very much http://blog.csdn.net/mybook201314/article/details/70173674 click to open the link
1, WebSocket introduction
WebSocket is a protocol for full-duplex communication provided by HTML5, typically a browser (or other client) communicating with a Web server. This makes it suitable for highly interactive Web applications, such as instant messaging chats.
The WebSocket protocol is a new network protocol based on TCP. It implements browser-to-server full-duplex (Full-duplex) communication-a popular explanation for the server to proactively send information to the client.
WebSocket was first referred to as a TCP connection in the HTML5 specification as a placeholder for the TCP-based socket API. [1] The WebSocket communication protocol was established by the IETF as standard RFC 6455 in 2011 and is supplemented by RFC7936 specifications.
Excerpt from: Baidu Encyclopedia-websocket 2, Spring+websocket
spring4.0 already support WebSocket, can go to check the official website.
Official website: Spring WebSocket
Note: This spring+websocket, oneself is not very familiar, just recently used to, study a bit, record processing, convenient later avoid take more detour. 3. Configure the Environment 3.1. Environment:
Spring-4.0.2.release
java1.7
apache-tomcat-7.0.75
1 2 3 4
MAVEN Build Project:
Pom.xml:
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId> jackson-core</artifactid>
<version>2.3.0</version>
</dependency>
< dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId> jackson-databind</artifactid>
<version>2.3.0</version>
</dependency>
1 2 3 4 5 6 7 8 9 10 11
SPRINGMVC:
<!--SPRINGMVC Begin--
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.0.2.RELEASE</version>
</ dependency>
<dependency>
<groupId>org.springframework</groupId>
< artifactid>spring-context-support</artifactid>
<version>4.0.2.RELEASE</version>
</dependency>
<!--SPRINGMVC End---
1 2 3 4 5 6 7 8 9 10 11 12 13 14
WebSocket:
<!--WebSocket---
<dependency>
<groupId>org.springframework</groupId>
< artifactid>spring-websocket</artifactid>
<version>4.0.2.RELEASE</version>
</ dependency>
<dependency>
<groupId>org.springframework</groupId>
< artifactid>spring-messaging</artifactid>
<version>4.0.2.RELEASE</version>
</ Dependency>
1 2 3 4 5 6 7 8 9 10 11 12
3.2, Servlet-api
The SERVLET-API must be 3.0+ to support websocket, so if not, update the jar package.
<dependency>
<groupId>javax.servlet</groupId>
<artifactid>javax.servlet-api </artifactId>
<version>3.1.0</version>
</dependency>
1 2 3) 4 5
3.3. Web. XML Configuration
and the namespace of Web. XML also make sure it's 3.0+,
Xml
<?xml version= "1.0" encoding= "UTF-8"?> <web-app
xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance "
xmlns=" Http://java.sun.com/xml/ns/javaee "
xmlns:web=" http://java.sun.com/xml/ns/javaee/web-app_3_0. xsd "
xsi:schemalocation=" Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0. The XSD "
version=" 3.0 ">
<!--WebSocket requires that the Servlet3.0 requires Web. XML 3.0 and above, and you want to configure this--and
< absolute-ordering/>
</web-app>
1 2 3 4 5 6 7 8 9 10
Code: <absolute-ordering/> should also be added at the beginning of Web. Xml.
And you have to add both the filter and the servlet asynchronously:
<async-supported>true</async-supported>
1
For example, the configuration of Springmvc in Web. XML should also be added:
<!--SPRINGMVC configuration Start--
<servlet>
<servlet-name>springMVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
< init-param>
<param-name>contextConfigLocation</param-name>
<