2014-01-13 71 views
2

我試圖運行websocket示例。Glassfish服務器在啓動時顯示錯誤

我的客戶端代碼是這個

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  
"http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
    <title>Web Socket Implementation</title> 
</head> 
<body> 
    <form> 
     <input id="textmessage" type="text"> 
     <input onclick="sendmessage();" value="Send Message" type="button"> 
    </form> 
<br><textarea id="messageTextArea" rows="10" cols="50"></textarea> 
    <script type="text/javascript"> 

    var webSocket=new 
      WebSocket("ws://localhost:8080/SimpleWebSocketProj1/serverendpoindemo"); 
    var messageTextArea=document.getElementById("messageTextArea"); 
    webSocket.onopen=function(message){processOpen(message);}; 
    webSocket.onmessage=function(message){processMessage(message);}; 
    webSocket.onclose=function(message){processClose(message);}; 
    webSocket.onerror=function(message){processError(message);}; 
    function processOpen(message) 
    { 
     messageTextArea.value +="Server Connect.." + "\n"; 
    } 

    function onmessage(message) 
    { 
     messageTextArea.value +="Receive from server..-->" + message.data 
        +"\n"; 
    } 

    function sendmessage() 
    { if(textmessage.vaue!="close") 
      { 
      webSocket.send(tesxtmessage.value); 
      messageTextArea.value +="Send to server..-->" +  
          textmessage.value +"\n"; 
      tesxtmessage.value=""; 
      } 
     else 
      webSocket.close(); 
    } 

    function processClose(message) 
    { 
     webSocket.send("Client disconnceted.."); 
     messageTextArea.value +="Server Disconnect.." + "\n"; 
    } 
    function processError(message) 
    { 
     messageTextArea.value +="Error while Connect..\n"; 
    } 
    </script> 
</body> 
</html> 

這是我的服務器的Java代碼

package com.ws.test; 

import javax.websocket.OnClose; 
import javax.websocket.OnError; 
import javax.websocket.OnMessage; 
import javax.websocket.OnOpen; 
import javax.websocket.server.ServerEndpoint; 

@ServerEndpoint("/serverendpoindemo") 
public class ServerEndpoinDemo 
{ @OnOpen 
public void handleOpen() 
{ 
    System.out.println("client is now connected.."); 
} 
@OnMessage 
public String handleMessage(String message) 
{ 
    System.out.println("receive from client.." +message); 
    String replymessage="echo " +message; 
    System.out.println("send to client.." +replymessage); 
    return replymessage; 

} 
@OnClose 
public void handleClose() 
{ 
    System.out.println("client is now disconnected.."); 
} 
@OnError 
public void handleError(Throwable t) 
{ 
    t.printStackTrace(); 
} 

} 

當我試圖在服務器上運行它顯示這樣 Eclipse插件錯誤無法溝通與GlassFish服務器,狀態是:CREDENTIAL_ERROR

回答

0

也許安裝玻璃魚有問題,請確保你有他從你的glassfish和eclipse中正確的JDK中修正了filepath。 當您製作一個新的動態Web項目時,請轉到:target runtime> glassfish 4並通過glassfish服務器目錄:C:.. \ glassfish4 \ glassfish 然後在同一個屏幕中添加一個JDK而不是JRE文件位置: C:.. \的Java \ jdk1.7.0_51。如果您沒有JDK下載它。擊中完成,它應該工作。

+0

@ user3241867:我已經做了它仍然我不能運行,我也嘗試在Eclipse靛藍和朱諾IDE,但尚未解決。 – noviceCodder

相關問題