Struts2+websocket error: Failed:error during WebSocket handshake:unexpected response code:404

Source: Internet
Author: User
Tags response code

The recent integration of WebSocket into the project, open Web pages will always encounter such errors.

There are 3 reasons for saying this online, but they are not for me, but they are also recorded.

1.struts2 intercepted the WS request. This invocation can attempt to empty the Web. XML, which is the problem if it can be connected. At this point, add the following in the Struts.xml configuration file:

<name= "Struts.action.excludePattern"  value= "ws://*"  ></constant>

The request to WS is not intercepted.

2.jar package conflict, the jar package in the project conflicts with the jar package in Tomcat.

3. Turn Java project into Web project and adjust the package load order.

Then it's your solution, the URL rule for the WS request is this: Address + port +endpoint path. If the endpoint is defined in a Java file:

@ServerEndpoint (value= "/echoendpoint")

and runs on local 8080 port, the URL is http://127.0.0.1:8080/echoendpoint

Java7 WebSocket only need to configure endpoint, the page JS can be connected, no servlet or other configuration, just pay attention to the next URL.

Struts2+websocket error: Failed:error during WebSocket handshake:unexpected response code:404

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.