Websocket 连接不适用于 Struts2

Websocket Connection is not working with Struts2

我已经从 https://github.com/slankka/websocket-with-struts2

Error : WebSocket connection  to 'ws://localhost:8080/websocket' failed: 

Web.xml

<!DOCTYPE web-app PUBLIC
    "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Struts2 Web Application</display-name>
<filter>
    <filter-name>struts2</filter-name>
    <filter-class>
        org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
    </filter-class>
</filter>
<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

Struts.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
    "http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
    <constant name="struts.action.excludePattern" value="/websocket*,^ws://.$"/>
    <package name="controllers" namespace="/"  extends="struts-default">
        <action name="homePage" class="io.github.slankka.controllers.HomeAction" method="home">
           <result name="SUCCESS">/home.jsp</result>
        </action>
    </package>
</struts>

ChatServer.java

package io.github.slankka.controllers;

import java.io.IOException;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.atomic.AtomicInteger;

import javax.websocket.*;
import javax.websocket.server.ServerEndpoint;

@SuppressWarnings("unused")
@ServerEndpoint("/websocket")
public class ChatServer {
...
}

URL : http://localhost:8080/web_socket_struts2_test/chat.jsp

Error : WebSocket connection to 'ws://localhost:8080/websocket' failed: 

也尝试了 Whosebug 的许多解决方案,但仍然没有任何效果。

您在 URL 中缺少 Web 应用程序上下文路径。

ws://localhost:8080/[CONTEXT_NAME]/websocket

有时上下文名称和项目名称相同。

示例:

ws://localhost:8080/web_socket_struts2_test/websocket