灰熊服务器索引页面不工作

Grizzly server index page not working

我有这个服务器设置和路由代码。

package net.randohinn.neo;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import org.glassfish.grizzly.http.server.HttpHandler;
import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.grizzly.http.server.Request;
import org.glassfish.grizzly.http.server.Response;

public class Main {

    public static HttpServer webServer;

    public static void main(String[] args) {
        webServer = HttpServer.createSimpleServer();
        webServer.getServerConfiguration().setName("Neo CMS");
        webServer.getServerConfiguration().addHttpHandler(
                new HttpHandler() {
                    public void service(Request request, Response response) throws Exception {
                        final SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
                        final String date = format.format(new Date(System.currentTimeMillis()));
                        response.setContentType("text/plain");
                        response.setContentLength(date.length());
                        response.getWriter().write(date);
                    }
                },
                "/");
        try {
            webServer.start();
            Thread.currentThread().join();
        } catch (IOException | InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}

如果我现在转到 localhost:8080,它告诉我路径 / 的资源不存在 :( 似乎它无法检测到首页的处理程序。这里可能有什么问题? 例如,将处理程序中的路径更改为 /time,工作正常。

尝试改变 //webServer = HttpServer.createSimpleServer(); //webServer.getServerConfiguration().setName("Neo CMS");

webServer = new HttpServer();
NetworkListener nl = new NetworkListener("Neo CMS", "localhost", 8080);
webServer.addListener(nl);