WebSocket 握手:意外响应代码:404 [英] WebSocket handshake: Unexpected response code: 404
问题描述
正在编写我的第一个 websocket 程序,并且收到 WebSocket 握手:意外响应代码:404",加载网页时出错.
Am writing my first websocket program and am getting "WebSocket handshake: Unexpected response code: 404", error while loading the webpage.
我使用的是 JDK 1.7 和 jboss 8 (wildfly8.0).
I am using JDK 1.7 and jboss 8 (wildfly8.0).
有人可以帮忙吗?
window.onload = init;
var socket = new WebSocket("ws://localhost:8080/WebsocketHome/actions");
socket.onmessage = onMessage;
然后在 html 中
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="websocket.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
推荐答案
谢谢大家的建议,我找到了答案.
Thank you guys for your suggestion, I found the answer.
我复制的代码来自 http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/HomeWebsocket/WebsocketHome.html 网站.
The code I copied is from http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/HomeWebsocket/WebsocketHome.html site.
问题是js文件中提到的url,他们提议的项目名称是WebsocketHome.我已将项目名称更改为 Websocket,因此我的 url 应为 ws://localhost:8080/Websocket/actions.
The problem was the url as mentioned in the js file and the project name they are proposing is WebsocketHome. I had changed the project name to Websocket thus my url should be ws://localhost:8080/Websocket/actions.
感谢您的支持.
这篇关于WebSocket 握手:意外响应代码:404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!