Spring-websocket is not used in SPRINGMVC environment __web

Source: Internet
Author: User
Tags response code

SPRING4 provides support for WebSocket, but online demos are used in the context of spring MVC.

In fact, Spring-websocket is not dependent on SPRINGMVC.

The key is to map the WebSocket address to the URL for triggering the front end.

Also, the first time WebSocket is invoked via HTTP.

In other words, the first request from the client is HTTP. Not websocket.

Here there is evidence of the author.

Open the browser console. We can see.


We can see that the HTTP response code is 101 and the HTTP request header has a upgrade field with a value of websocket.

Now we map the WebSocket code to the servlet

  Map the WebSocket address to the servlet
    @Override  
    protected void DoPost (HttpServletRequest req, httpservletresponse RESP)  
            throws Servletexception, IOException {  
  
        ApplicationContext context = Webapplicationcontextutils  
                . Getwebapplicationcontext (Req.getservletcontext ());

        WebSocket's processor
        Websockethttprequesthandler handler = new Websockethttprequesthandler (  
                Context.getbean (" MyHandler ", Myhandler.class));  
        WebSocket Handshake Processor
        list


Full code address in: http://download.csdn.net/detail/u013803262/9899775


Reference from: http://blog.csdn.net/aitangyong/article/details/50533414

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.