WebSocket连接不使用Strut2
我举了例子 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:
也尝试了 stackoverflow 上的许多解决方案,但还没有任何效果。
I have taken example from
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://.quot;/>
<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:
Tried many solutions from stackoverflow as well but nothing work yet.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您缺少URL中的Web应用程序上下文路径。
有时,上下文名称和项目名称相同。
例子:
You are missing web application context path in the URL.
Sometimes context name and project name are the same.
EXAMPLE: