最近把websocket集成进项目里面来,打开网页总是会遇到这样的错误。

网上说的原因有3种,但是都不适合我,但是也记录下。

1.struts2截拦掉了ws的请求。这种援用可以尝试把web.xml清空,如果可以连接,则是这个问题。此时在struts.xml的配置文件中添加:

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

对ws的请求不截拦。

2.jar包的冲突,项目里的jar包跟tomcat中的jar包冲突。

3.把java project 转化为 web project,调整包加载顺序。

然后就是自己的解决方法,ws请求的url规则是这样的:地址+端口+endpoint路径。如果在java文件中定义了端点:

@ServerEndpoint(value="/echoendpoint")

并且在本地8080端口运行,则url为 http://127.0.0.1:8080/echoendpoint

java7的websocket只需要配置endpoint,页面的JS就可以连接上,无需servlet或其他配置,只需注意下url。

struts2+websocket报错:failed: Error during WebSocket handshake: Unexpected response code:404的更多相关文章

  1. WebSocket connection to,Error during WebSocket handshake: Unexpected response code: 404

    使用标准的JSR 356注解时,需要使用tomcat 8.x版本,如果使用tomcat 7.x的版本,则需要继承WebSocketServlet,否则会报WebSocket connection to ...

  2. WebSocket handshake: Unexpected response code: 404

    在执行    http://www.cnblogs.com/best/p/5695570.html  提供的 websocket时候, 报错了 “WebSocket handshake: Unexpe ...

  3. 微信小程序WebSocket报错:Error during WebSocket handshake: Sent non-empty 'Sec-WebSocket-Protocol' header but no response was received

    Error during WebSocket handshake: Sent non-empty 'Sec-WebSocket-Protocol' header but no response was ...

  4. easyswoole报错:failed: Error during WebSocket handshake: Unexpected response code: 200

    WebSocket connection to 'ws://www.xxxx.com/xxx/xx' failed: Error during WebSocket handshake: Unexpec ...

  5. nginx反向代理 报错:Error during WebSocket handshake: Unexpected response code: 403

    遇到nginx报错:websocket wss failed: Error during WebSocket handshake: Unexpected response code: 403 serv ...

  6. Vue脚手架创建项目出现 (Failed to download repo vuejs-templates/webpack: Response code 404)

    搭建好(脚手架2.X版本)环境像往常一样使用vue init webpack xxxx 创建项目可以是没多久就开始报错了 报错结果就是:vue-cli · Failed to download rep ...

  7. vue-cli 安装失败Failed to download repo vuejs-templates/vuedemo: Response code 404 (Not Found)

    还原问题现场: 第一次使用vue init webpack projectName的时候,由于操作失误,执行了两次npm install -g vue-cli,然后再使用vue init webpac ...

  8. hive 报错FAILED: Error in metadata: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.metastore.HiveMetaStoreClient FAILED: Execu

    使用hive一段时间以后,今天在使用的时候突然报错,如下: hive> show databases;FAILED: Error in metadata: java.lang.RuntimeEx ...

  9. vue-cli 安装失败Failed to download repo vuejs-templates/webapck-simple: Response code 404 (Not Found)

    新学习vue的萌新们经常会遇到各种各样的坑.例如上面这个报错.这个一般是命令行面板写错单词导致. 正确:vue init webpack-simple .(注意"."点,指当前目录 ...

随机推荐

  1. TS流解析 二 *****

    1.TS格式介绍 TS:全称为MPEG2-TS.TS即"Transport Stream"的缩写.它是分包发送的,每一个包长为188字节(还有192和204个字节的包).包的结构为 ...

  2. 控件m

    窗体的事件:删除事件:先将事件页面里面的挂好的事件删除,再删后台代码里面的事件 Panel是一个容器 1.Label -- 文本显示工具Text:显示的文字取值.赋值:lable1.Text 2.Te ...

  3. 学习笔记之Android

    Android 开发专区 - 开源中国社区 http://www.oschina.net/android 探索 Android Studio | Android Studio https://deve ...

  4. POI导出Excel和InputStream存储为文件

    POI导出Excel和InputStream存储为文件   本文需要说明的两个问题 InputStream如何保存到某个文件夹下 POI生成Excel POI操作utils类 代码如下.主要步骤如下: ...

  5. [Python] String strip() Method

    Description The method strip() returns a copy of the string in which all chars have been stripped fr ...

  6. python的接口

    写法一: class Payment: def pay(self, money): raise NotImplementedError class Alipay(Payment): def pay(s ...

  7. 跟我学算法- tensorflow 卷积神经网络训练验证码

    使用captcha.image.Image 生成随机验证码,随机生成的验证码为0到9的数字,验证码有4位数字组成,这是一个自己生成验证码,自己不断训练的模型 使用三层卷积层,三层池化层,二层全连接层来 ...

  8. 使用D3D渲染YUV视频数据<转>

    源代码下载 转载地址:http://blog.csdn.net/dengzikun/article/details/5824874 源码地址:http://download.csdn.net/down ...

  9. SQL优化的部分内容

    为什么要优化:      随着实际项目的启动,数据库经过一段时间的运行,最初的数据库设置,会与实际数据库运行性能会有一些差异,这时我们         就需要做一个优化调整.   数据库优化这个课题较 ...

  10. ROS 消息发布器和订阅器Publisher, Subscriber

    博客参考:https://www.2cto.com/kf/201705/639776.html 1.编写发布器节点节点(Node) 是指 ROS 网络中可执行文件.接下来,将会创建一个发布器节点(“t ...