作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在谷歌上找到了很多关于这个问题的引用,但没有答案。我正在使用最新版本的 jetty (8.1.2.v20120308),但似乎无法获得能够使用 session 的嵌入式 servlet。该示例当然是在 Scala 中的,但它应该对任何 Java 程序员都可读。
val server = new Server();
val connector = new SelectChannelConnector()
connector.setPort(Integer.getInteger("jetty.port", 8080).intValue())
server.setConnectors(Array(connector))
val webapp = new ServletContextHandler(ServletContextHandler.SESSIONS)
webapp.setContextPath("/")
webapp.setResourceBase(webDir)
webapp.setServer(server)
val brzyServ = new ServletHolder(new BrzyDynamicServlet())
webapp.addServlet(brzyServ, "*.brzy")
server.setHandler(webapp);
server.start()
...
log.debug("session manager: {}",req.asInstanceOf[Request].getSessionManager)
val session = req.getSession
...
java.lang.IllegalStateException: No SessionManager
at org.eclipse.jetty.server.Request.getSession(Request.java:1173)
DEBUG org.eclipse.jetty.server.session - sessionManager=org.eclipse.jetty.server.session.HashSessionManager@2a8ceeea
DEBUG org.eclipse.jetty.server.session - session=null
最佳答案
我相信问题来自于您正在实例化 ServletContextHandler
的事实。而不是 WebappContext
试试
val webapp = new WebappContext();
val webapp = new ServletContextHandler(ServletContextHandler.SESSIONS)
webapp.setSessionHandler(new SessionHandler())
[...]construction of a context with ServletHandler and optionally session and security handlers [...]
optionally
可能是这里的关键。
关于embedded-jetty - 嵌入式码头 - IllegalStateException : No SessionManager,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9862216/
我是一名优秀的程序员,十分优秀!