jspjakarta-eeglassfishtyrus

How to deploy .jsp with Tyrus websocket server?


So I have a server endpoint that gets deployed via a websocket server using Tyrus. Several swing apps I have written use this server endpoint to communicate. However I would like to also deploy a .jsp web page on this same server.

As of now I am able to access the .jsp page however it displays as code in the browser rather than generating the proper html.

package com.server;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

import javax.websocket.DeploymentException;

import org.glassfish.tyrus.server.Server;

import com.util.DiscordLogger;

public class Main {

    public static DiscordLogger discord = new DiscordLogger();

    public static void main(String args[]) {
        final Map<String, Object> serverProperties = new HashMap<String, Object>();
        serverProperties.put(Server.STATIC_CONTENT_ROOT, "./WebContent"); //folder with .jsp file
        Server server = new Server("localhost", 8080, "/Server", serverProperties,
                com.websocket.WebSocketServer.class);
        try {
            server.start();
            System.out.println("Press any key to stop the server..");
            new Scanner(System.in).nextLine();
        } catch (DeploymentException e) {
            throw new RuntimeException(e);
        } finally {
            server.stop();
        }
    }

}

Solution

  • Tyrus is purely an implementation of WebSockets, and does not support JSP. To use JSPs, you need a servlet container, such as Tomcat or Payara Micro.