java web 程序,建立了一个服务器端点类
@ServerEndpoint("/echo")
public class WebSocketTest { static Set<Session> all = Collections.synchronizedSet(new HashSet<Session>());
@OnOpen
public void onOpen(Session session) throws IOException {
...
}
@OnClose
public void onClose(Session session) {
...
}
@OnMessage
public void echo(Session session, String message) throws IOException {
...
}
@OnError
public void onError(Throwable t) {
....
}
}
index.html文件
<!DOCTYPE html>
<html>
<head>
<title>Testing websockets</title>
</head>
<body>
<textarea id="a" readonly="readonly" rows="10" cols="50"></textarea>
<br />
<input type="text" id="m" size="50" />
<input type="button" value="Send" onClick="send();" />
<script type="text/javascript">
var url = ((window.location.protocol == "https:") ? "wss:" : "ws:")
+ "//" + window.location.host
+ "/WebSocket/echo";
alert(url);
var ws =
new WebSocket(url);
ws.onopen = function() {
console.log("open");
};
ws.onmessage = function(evt) {
document.getElementById("a").value="12";
};
ws.onclose = function(evt) {
console.log("WebSocketClosed!");
};
ws.onerror = function(evt) {
console.log("WebSocketError!");
};
function send() {
var m=document.getElementById("m");
ws.send(m.value);
}
</script>
</body>
</html>
这个程序部署在tomcat上没什么问题,部署在weblogic上
火狐报
Firefox 无法建立到 ws://localhost:7008/WebSocket/echo.ws 服务器的连接。的错误
IE报ws未定义的错
请教各位这是什么原因。
@ServerEndpoint("/echo")
public class WebSocketTest { static Set<Session> all = Collections.synchronizedSet(new HashSet<Session>());
@OnOpen
public void onOpen(Session session) throws IOException {
...
}
@OnClose
public void onClose(Session session) {
...
}
@OnMessage
public void echo(Session session, String message) throws IOException {
...
}
@OnError
public void onError(Throwable t) {
....
}
}
index.html文件
<!DOCTYPE html>
<html>
<head>
<title>Testing websockets</title>
</head>
<body>
<textarea id="a" readonly="readonly" rows="10" cols="50"></textarea>
<br />
<input type="text" id="m" size="50" />
<input type="button" value="Send" onClick="send();" />
<script type="text/javascript">
var url = ((window.location.protocol == "https:") ? "wss:" : "ws:")
+ "//" + window.location.host
+ "/WebSocket/echo";
alert(url);
var ws =
new WebSocket(url);
ws.onopen = function() {
console.log("open");
};
ws.onmessage = function(evt) {
document.getElementById("a").value="12";
};
ws.onclose = function(evt) {
console.log("WebSocketClosed!");
};
ws.onerror = function(evt) {
console.log("WebSocketError!");
};
function send() {
var m=document.getElementById("m");
ws.send(m.value);
}
</script>
</body>
</html>
这个程序部署在tomcat上没什么问题,部署在weblogic上
火狐报
Firefox 无法建立到 ws://localhost:7008/WebSocket/echo.ws 服务器的连接。的错误
IE报ws未定义的错
请教各位这是什么原因。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货