Tag: httpsession

Spring MVC何时会自动生成HttpSession?

使用AutoWired HttpSession的问题: LoginController调用LoginService传递HttpServletRequest作为参数。 我已经在其他几个带注释的类中自动assembly了HttpSession(但不是在LoginService中): @Autowired private HttpSession httpSession; 在LoginService类中,如果我尝试通过调用request.getSession(false)来获取会话,则在某些情况下我会收到null。 如果我尝试通过调用request.getSession(true)来获取会话,我最终会得到两个HttpSession对象(一个在这里,另一个通过AutoWiring)。 如果我在LoginServic类中自动assemblyHttpSession并从那里使用会话,那么我也将以两个HttpSession对象结束。 何时会创建完全自动assembly的HttpSession? 处理这种情况的最佳方法是什么? 谢谢!

如何从SessionID获取HttpSession对象?

我想根据某些事件使用户会话无效。 我存储了他们的sessionID,如何从这个ID获取他们的HttpSession? 不推荐使用HttpSessionContext类,无需替换。

Java HttpSession属性存储在哪里?

对象是否已序列化并发送给用户并返回每个连接(存储在cookie中)? 或者它们是否存储在服务器堆中,而cookie只是一个非常小的标识符? 有关此主题的任何信息都会有所帮助。 谢谢

为什么getSession()在后续请求中在短时间内返回相同的会话?

我一个接一个地发送$.getJSON (HTTP GET)请求(使用不同的数据)(假设我们有request1和request2)。 我可以在FF和Chrome的开发者工具中看到我有相同的cookie:JSESSIONID=FD0D502635EEB67E3D36203E26CBB59A标题字段。 在服务器端,我尝试获取会话: HttpSession session = request.getSession(); boolean isSessionNew = session.isNew(); String sessionId = session.getId(); String cookieFromRequestHeader = request.getHeader(“cookie”); 如果我为这两个请求打印这些变量, request1: isSessionNew:真 cookieFromRequestHeader:JSESSIONID = FD0D502635EEB67E3D36203E26CBB59A session.getId():9212B14094AB92D0F7F10EE21F593E52 请求2: isSessionNew:真 cookieFromRequestHeader:JSESSIONID = FD0D502635EEB67E3D36203E26CBB59A session.getId():E8734E413FA3D3FEBD4E38A7BF27BA58 如您所见,服务器在request.getSession()上清楚地为request2创建了一个新会话。 但为什么会这样呢? 它理论上应该是同步的,并为您提供与第一个请求(首先达到此代码)创建的会话相同的会话。 现在,为了确保会话创建已同步,我执行了以下操作: @Autowired private ServletContext servletContext; … synchronized (servletContext) { HttpSession session = request.getSession(); boolean isSessionNew = session.isNew(); String […]

Java HttpSession

是否在java servlet中创建了HttpSession HttpSession s = request.getSession(); ? 在我的代码中我没有写那个,但是当我使用if (request.getSession(false) == null) … ,它不起作用。 为什么?

存储并使不同用户的Java HttpSession无效

好的。 我想要做的是,当我更新用户时,可以使他们当前拥有的任何会话无效,以强制刷新凭据。 我不关心能够直接访问特定于会话的用户数据。 理想情况下,我也可以通过类似的方式将用户限制为一个会话。 我尝试做的是使用用户名作为键创建一个HashMap,并使用HttpSession作为值(我的实际设置稍微复杂一些,但在重复看似无法解释的失败之后,我将其归结为这个简单的测试)。 但是,每当我试图告诉检索到的HttpSession无效时,它似乎使当前的[admin]会话无效。 HttpSession是否与当前请求密不可分? 或者有一种完全不同的方式来处理这个问题? 如果它碰巧重要,我正在使用Jetty 6.1.26。

从httpsession中检索浏览器区域设置?

是否可以从httpsession对象(javax.servlet.http.HttpSession)派生首选语言? 有可能从servletrequest获得它,但我没有。 谢谢你的任何想法。 斯文

在最初接收的线程之外访问HttpSession

我正在使用Spring 3.当控制器获得请求时,它将控制传递给在Service bean中使用@Async注释的方法someMethod() ,然后返回。 当我访问someMethod() HttpSession对象时,我收到此exception java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: […]

HttpSessionListener.sessionCreated()未被调用

我有一个非常简单的Servlet和一个非常简单的HttpSessionListener: @WebServlet(“/HelloWorld”) public class HelloWorld extends HttpServlet { private static final long serialVersionUID = 1L; @Override public void init(ServletConfig config) throws ServletException { super.init(config); getServletContext().setAttribute(“applicationHits”, new AtomicInteger(0)); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println(“get”); ((AtomicInteger) request.getServletContext().getAttribute(“applicationHits”)).incrementAndGet(); ((AtomicInteger) request.getSession(true).getAttribute(“sessionHits”)).incrementAndGet(); request.setAttribute(“requestHits”, 0); getServletContext().getRequestDispatcher(“/view/HelloWorld.jsp”).forward(request, response); } } @WebListener public class SessionListener implements HttpSessionListener […]

从HttpSessionListener获取SessionScoped bean?

大家好。 我正在尝试在HttpSessionListener中获取会话bean,以便当用户注销或会话到期时,我可以删除用户在应用程序中创建的一些文件。 我猜测会话bean不存在,因为会话被销毁了。 我希望仍然删除这些文件的一些方法。 谢谢您的帮助。 @WebListener public class SessionListener implements HttpSessionListener { @Override public void sessionCreated(HttpSessionEvent se) { HttpSession session = se.getSession(); System.out.print(getTime() + ” (session) Created:”); System.out.println(“ID=” + session.getId() + ” MaxInactiveInterval=” + session.getMaxInactiveInterval()); } @Override public void sessionDestroyed(HttpSessionEvent se) { HttpSession session = se.getSession(); FacesContext context = FacesContext.getCurrentInstance(); //UserSessionBean userSessionBean = (UserSessionBean) context.getApplication().evaluateExpressionGet(context, […]