In spring using websockets getting this error,uncaught type error: onrecieve is not a function(..) stomp.js

In spring using websockets getting this error,uncaught type error: onrecieve is not a function(..) stomp.js

我收到这个错误:

uncaught type error: onrecieve is not a function(..) stomp.js

谁能帮助我并提供使用 stockjs、stomp 和 jars 的完整设置?

我的file:home.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Reload..</title>




<%--  <script type="text/javascript" src='<c:url  value="/static/scripts/jquery.js"/>'></script>  --%>
<script type="text/javascript" src='<c:url value="/static/scripts/sockjs-  0.3.4.js"/>'></script> 
  <script type="text/javascript" src='<c:url value="/static/scripts/stomp.js"/>'></script>

   <script type="text/javascript">

   var stompClient=null;

  var onDebug = function(m) {
    console.log('DEBUG', m);
  };

  var connect=function(){
  var socket = new SockJS("/testwebsockets/portfolio");
    stompClient = Stomp.over(socket);
   stompClient.connect({}, function(frame) {
    console.log('Connecteds: ' + frame);
 stompClient.debug = onDebug;
stompClient.subscribe("/topic/portfolio",{},function(msgput){
    console.log("msg:"+msgput.body);
  });
},function(error){
  alert(error);
});
};





  var sendMessage=function(){
  stompClient.debug = onDebug;
  stompClient.send("/app/portfolio",   {},JSON.stringify({from:'kk',text:'hello'}));
  };



 </script>
 </head>
<body>
 <div>
            <button id="connect" onclick="connect();">Connect</button>


        <br />
        <div id="conversationDiv">

            <button id="sendMessage" onclick="sendMessage();">Send</button>

        </div>
    </div>


  </body>
  </html>

那是 jsp 文件,使用 Javascript 代码连接到 websockets。它确实连接了,但是从控制器收到它时收到此错误:

uncaught type error: onrecieve is not a function(..) stomp.js

Opening Web Socket...
stomp.js;jsessionid=45714C4BB09BD6111D49A41D92FBBAC0:130 Web Socket Opened...
stomp.js;jsessionid=45714C4BB09BD6111D49A41D92FBBAC0:130 >>> CONNECT
accept-version:1.1,1.0
heart-beat:10000,10000

<<< CONNECTED
version:1.1
heart-beat:0,0

connected to server undefined
(index):34 Connecteds: CONNECTED
heart-beat:0,0
version:1.1

DEBUG >>> SUBSCRIBE
id:sub-0
destination:/topic/portfolio

DEBUG >>> SEND
destination:/app/portfolio
content-length:28

{"from":"kk","text":"hello"}

DEBUG <<< MESSAGE
destination:/topic/portfolio
content-type:application/json;charset=UTF-8
subscription:sub-0
message-id:h8_q6giw-0
content-length:48

{"from":"kk","text":"hello","timeStamp":"08:26"}

stomp.js;jsessionid=45714C4BB09BD6111D49A41D92FBBAC0:288 Uncaught TypeError: onreceive is not a function(…)(anonymous function) @ stomp.js;jsessionid=45714C4BB09BD6111D49A41D92FBBAC0:288REventTarget.dispatchEvent @
sockjs-0.3.4.js;jsessionid=45714C4BB09BD6111D49A41D92FBBAC0:84SockJS._dispatchMessage @
sockjs-0.3.4.js;jsessionid=45714C4BB09BD6111D49A41D92FBBAC0:1025SockJS._didMessage @
sockjs-0.3.4.js;jsessionid=45714C4BB09BD6111D49A41D92FBBAC0:1083that.ws.onmessage @
sockjs-0.3.4.js;jsessionid=45714C4BB09BD6111D49A41D92FBBAC0:1215

您的问题源于您传递给 subscribe 方法的一个错误的额外参数。

stompClient.subscribe("/topic/portfolio",{},function(msgput){
    console.log("msg:"+msgput.body);
});

应该变成:

stompClient.subscribe("/topic/portfolio",function(msgput){
    console.log("msg:"+msgput.body);
});