【发布时间】:2013-10-03 12:39:45
【问题描述】:
我在 Google 上搜索和 stackoverflow 了很多,但无法让它工作。这是我的代码。 我在 subscribe 方法中设置了一个会话属性“topic”,但在 sessionDestroyed 中我将其设置为 null。 SO 上的This question 似乎与我的相关,但不能解决问题。
@Path("/jpubsub/{topic}")
public class JMSSubscribe implements HttpSessionListener, ServletContextListener, MessageListener, ExceptionListener {
@GET
public subscribe(@javax.ws.rs.core.Context HttpServletRequest request) {
HttpSession session = request.getSession();
session.setAttribute("topic", "1");
}
@Override
public void sessionCreated(HttpSessionEvent hse) {
HttpSession session = hse.getSession();
System.out.println("Created Session - ID : " + session.getId());
}
@Override
public void sessionDestroyed(HttpSessionEvent hse) {
System.out.println("Destroyed Session - ID : " + hse.getSession().getId());
System.out.println("Topic ID sessionDestroyed - " + hse.getSession().getAttribute("topic"));
}
请帮忙。
PS:当我在sessionCreated() 中设置属性时,我会在sessionDestroyed() 中得到它。
是因为我使用了不同的会话对象吗?另外,当我打印会话 ID 时。我在所有 3 种方法中都获得了相同的会话 ID。
请询问是否需要任何其他代码。
【问题讨论】:
-
如果您对某个问题投反对票,请给出理由。
-
你为什么将 SessionListener 与 JMS MessageListener 一起使用?
标签: java session httpsession