- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
目前在我的应用程序中,如果我转到 http://localhost:8181/index.htm
它工作得很好,如果我转到 http://localhost:8181
我收到 404 错误。如何让 Grizzly 默认加载 index.htm 页面?
final HttpServer server = HttpServer.createSimpleServer(".", 8181);
WebappContext ctx = new WebappContext("Socket", "/");
//enable annotation configuration
ctx.addContextInitParameter("contextClass", "org.springframework.web.context.support.AnnotationConfigWebApplicationContext");
ctx.addContextInitParameter("contextConfigLocation", "com.production");
//allow spring to do all of it's stuff
ctx.addListener("org.springframework.web.context.ContextLoaderListener");
//enable web socket support
final WebSocketAddOn addon = new WebSocketAddOn();
for (NetworkListener listener : server.getListeners()) {
listener.registerAddOn(addon);
//if false, local files (html, etc.) can be modified without restarting the server
listener.getFileCache().setEnabled(false);
}
//add jersey servlet support
ServletRegistration jerseyServletRegistration = ctx.addServlet("JerseyServlet", new ServletContainer());
jerseyServletRegistration.setInitParameter("com.sun.jersey.config.property.packages", "com.production.resource");
jerseyServletRegistration.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", "true");
jerseyServletRegistration.setLoadOnStartup(1);
jerseyServletRegistration.addMapping("/api/*");
//add atmosphere servlet support
AtmosphereServlet atmosphereServlet = new AtmosphereServlet();
AtmosphereFramework f = atmosphereServlet.framework();
ReflectorServletProcessor r = new ReflectorServletProcessor();
r.setServletClassName("com.sun.jersey.spi.spring.container.servlet.SpringServlet");
f.addAtmosphereHandler("/socket/*", r);
ServletRegistration atmosphereServletRegistration = ctx.addServlet("AtmosphereServlet", atmosphereServlet);
atmosphereServletRegistration.setInitParameter("org.atmosphere.websocket.messageContentType", "application/json");
atmosphereServletRegistration.setInitParameter("com.sun.jersey.config.property.packages", "com.production.resource");
atmosphereServletRegistration.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", "true");
//atmosphereServletRegistration.addMapping("/socket/*");
atmosphereServletRegistration.setLoadOnStartup(1);
//serve static assets
StaticHttpHandler staticHttpHandler = new StaticHttpHandler("src/main/web");
server.getServerConfiguration().addHttpHandler(staticHttpHandler, "/");
//deploy
logger.info("Deploying server...");
ctx.deploy(server);
最佳答案
你没有提到你使用的是什么版本的灰熊,但是从 2.2.19 开始:
看起来如果您将 index.htm
更改为 index.html
,默认页面应该可以正常工作。
如果它不存在或者由于某种原因您不能更改您的文件名,您可以简单地扩展 StaticHttpHandler 并覆盖 handle
方法以使其执行您想要的操作。
关于java - 如何在 Grizzly 中设置默认索引页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15976015/
Maven: org.glassfish.grizzly grizzly-websockets 2.3.1
启动 GlassFish 4.1.1 服务器(Grizzly Framework 2.3.23)时,显示以下警告消息:无法初始化实例。类=接口(interface) org.glassfish.gri
下面是启动 Grizzly Http Server 的代码。如果我按任何键,服务器就会停止。有什么办法让它活着。 Jetty 有 join() 方法,不会退出主程序。灰熊中是否也有类似的东西。 pub
我已经搜索了很多,但仍然不明白使用 Grizzly 是否意味着我可以免受这些攻击,或者我应该付出更多努力? 目前,我在程序中所做的唯一一件事就是通过以下代码将资源类(由 @Path 注释 - 我正在使
我正在使用 Jersey Grizzly,并且想要对 Grizzly 实现基本身份验证。我按如下方式创建 grizzly 服务器: ResourceConfig rc = new PackagesRe
有没有办法绑定(bind)grizzly对我的 Java 应用程序是动态的/透明的(可能通过使用 spring)?或者是 Web 容器的 IO 处理部分(例如 Glassfish)? 最佳答案 您的意
我有这个服务器设置和路由代码。 package net.randohinn.neo; import java.io.IOException; import java.text.SimpleDateFo
我已将此示例实现到我的应用程序中: https-clientserver-grizzly 这是来自该链接的 Server.java: public class Server { private
我已经使用 maven 设置了一个独立的 grizzly/jersey 服务器并引用了以下依赖项 org.glassfish.grizzly grizzly-http-server 2.
我正在尝试使用 grizzly 2.3 Web 服务器将 MyHttpHandler 映射到自定义 url,如下所示(应该是 RESTfull url,如 /entity/42/attribute):
我创建了一个 grizzly Web 服务器,从 tomcat 运行我的 Jersey 应用程序,以加快测试速度。 我是一个 grizzly 初学者,但是通过网络我将一些代码行放在一起,以便在不到一个
目前在我的应用程序中,如果我转到 http://localhost:8181/index.htm 它工作得很好,如果我转到 http://localhost:8181 我收到 404 错误。如何让 G
我创建了一个返回 JSON 的 Grizzly 服务器。效果很好: final ResourceConfig resourceConfig = new ResourceConfig().pac
如何关闭 Grizzly 的日志记录? 我想关闭以下日志记录: Okt 18, 2018 8:42:24 AM org.glassfish.grizzly.http.server.NetworkLis
我正在使用带有嵌入式版本的 Grizzly 的 Jersey,我只想在本地主机上绑定(bind)/监听。我正在通过创建调用使用 GrizzlyWebContainerFactory 创建 Thread
我写了下面的测试代码: @Test public void testLeakWithGrizzly() throws Throwable { ExecutorService executor
如何设置或增加连接限制或最大值。我创建的 grizzly HttpServer 中工作线程的池大小: HttpServer server = HttpServer.createSimpleServer
我正在使用 Grizzly HttpServer,它注册了两个 HttpHandler 实例: 在 /api/* 下有一个 Jersey REST 风格的应用程序,提供产品的 API,并且 在 /*
我有一个在嵌入式 Grizzly 上运行的 Jersey 应用程序,其初始化如下: HttpServer httpServer = GrizzlyServerFactory.createHttpSer
本文整理了Java中org.glassfish.grizzly.websockets.WebSocketEngine类的一些代码示例,展示了WebSocketEngine类的具体用法。这些代码示例主要
我是一名优秀的程序员,十分优秀!