Error code 200 and 404 websocket on tomcat 7.0.53 Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Error code 200 and 404 websocket on tomcat 7.0.53 without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I am using tomcat 7.0.53 to make websocket code and keep getting error code 200 when I use a / for the websocket location and error code 404 when I use /echo for the websocket location. I have no clue why it is not working. Below is the code for my programs html and java side.

Java side:

package wsapp;

import java.util.ArrayList;

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

@ServerEndpoint(value = "/echo")
public class WsChat{
//notice:not thread-safe
private static ArrayList<Session> sessionList = new ArrayList<Session>();

public void onOpen(Session session){
        //asynchronous communication
    }catch(IOException e){}

public void onClose(Session session){

public void onMessage(String msg){
        for(Session session : sessionList){
            //asynchronous communication
    }catch(IOException e){}

HTML Side:

<!DOCTYPE html>
    <meta charset="utf-8">
    <title>Tomcat WebSocket Chat</title>
        var ws = new WebSocket("ws://localhost:8080/echo");
        ws.onopen = function(){
        ws.onmessage = function(message){
            document.getElementById("chatlog").textContent += + "n";
        function postToServer(){
            document.getElementById("msg").value = "";
        function closeConnect(){
    <textarea id="chatlog" readonly></textarea><br/>
    <input id="msg" type="text" />
    <button type="submit" id="sendButton" onClick="postToServer()">Send!</button>
    <button type="submit" id="sendButton" onClick="closeConnect()">End</button>


The URL for the website was http://localhost:8080/websocket/. However in the code

var ws = new WebSocket("ws://localhost:8080/echo");

is being used instead of the correct way which is var ws = new WebSocket("ws://localhost:8080/websocket/echo"); . After that is done the handshake and communicating with the sockets works correctly.

We are here to answer your question about Error code 200 and 404 websocket on tomcat 7.0.53 - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji