Reputation: 654
I have taken example from https://github.com/slankka/websocket-with-struts2
Error : WebSocket connection to 'ws://localhost:8080/websocket' failed:
<!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>
<?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>
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:
Tried many solutions from stackoverflow as well but nothing work yet.
Upvotes: 1
Views: 266
Reputation: 1
You are missing web application context path in the URL.
ws://localhost:8080/[CONTEXT_NAME]/websocket
Sometimes context name and project name are the same.
EXAMPLE:
ws://localhost:8080/web_socket_struts2_test/websocket
Upvotes: 1