初学WebSocket,做了一个Demo,出现404错误。websocket连接websocket连接
WebSocket connection to 'ws://localhost:8088/chat/begin?uname=xiaoming' failed: Error during WebSocket handshake: Unexpected response code: 404
JS代码:
var chat={};
chat.socket=null;
var uname="<%=request.getSession().getAttribute("uname")%>"
function conn(){
connect("ws://localhost:8088/chat/begin?uname="+uname);
}
function connect(host){
if("WebSocket" in window){
chat.socket=new WebSocket(host);
}else if("MoWebSocket" in window){
chat.socket=new MoWebSocket(host);
}else{
console.log("当前浏览器不支持WebSocket");
return;
}
}
后台终端代码:
@ServerEndpoint("/begin")
public class ChatServer {
@OnOpen
public void start(Session session){
System.out.println(session.getQueryString());
}
}
使用的是eclipse开发,Web服务器使用Tomcat7,jdk版本是1.8。
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/ruanjian/article-33264-1.html
同志们是取向差异
我们确实盼着台独分子好好折腾