httpsession

httpSession in Grails

爷,独闯天下 提交于 2020-01-06 08:18:41
问题 I need to access the domain class User of the current session. The following code works: class RatingController { def rate = { def rating = params.rating def artist = Artist.get( params.id ) def user = User.get(1) user.addToRatings(new Rating(artist:artist, rating:rating)) user.save() render(template: "/artist/rate", model: [artist: artist, rating: rating]) } } But instead of explicitly get the user with ID equal 1 (User.get(1)) I need to access the user of the current session. I tried the

How to propagate CDI session beans from HTTP session to WebSocket session?

自闭症网瘾萝莉.ら 提交于 2020-01-05 13:38:14
问题 I googled a lot for this problem before posting this question and Accessing HttpSession from HttpServletRequest in a Web Socket @ServerEndpoint is one of the best Questions/Answers I was able to found, but it appears to not solve my problem. I was able to access HttpSession from websocket in this way, but I can't access the same CDI session bean instances as from normal HTTP requests. I tried to store in session the HttpSessionContextImpl Weld instance too and tried to use it on WebSocket

How to propagate CDI session beans from HTTP session to WebSocket session?

二次信任 提交于 2020-01-05 13:37:30
问题 I googled a lot for this problem before posting this question and Accessing HttpSession from HttpServletRequest in a Web Socket @ServerEndpoint is one of the best Questions/Answers I was able to found, but it appears to not solve my problem. I was able to access HttpSession from websocket in this way, but I can't access the same CDI session bean instances as from normal HTTP requests. I tried to store in session the HttpSessionContextImpl Weld instance too and tried to use it on WebSocket

JSP Servlet session invalidate() does not make session null

大兔子大兔子 提交于 2020-01-03 18:46:45
问题 I have three simple HttpServlet classes in my JSP project, "LoginServlet", "LogoutServlet" and "ProfileServlet". LoginServlet: log in user by setting "name" attribute to session LogoutServlet: log out user and invalidate session ProfileServlet: display user welcome info if user has logged in The last two servlets are as below that I reckon are problematic. @SuppressWarnings("serial") public class LogoutServlet extends HttpServlet { protected void doGet(HttpServletRequest request,

JSP Servlet session invalidate() does not make session null

痴心易碎 提交于 2020-01-03 18:46:33
问题 I have three simple HttpServlet classes in my JSP project, "LoginServlet", "LogoutServlet" and "ProfileServlet". LoginServlet: log in user by setting "name" attribute to session LogoutServlet: log out user and invalidate session ProfileServlet: display user welcome info if user has logged in The last two servlets are as below that I reckon are problematic. @SuppressWarnings("serial") public class LogoutServlet extends HttpServlet { protected void doGet(HttpServletRequest request,

How to obtain an HttpSession Object from SessionID?

拈花ヽ惹草 提交于 2020-01-02 06:35:34
问题 I want to invalidate sessions of users based on some Event. I store their sessionID, how to get their HttpSession from this ID? The HttpSessionContext class is deprecated with no replacement. 回答1: Servlet 2.2 specifically deprecated this for security reasons so there shouldn't be any official way to do this. Not recommended but you can can try to use Manager.findSession() if you use Tomcat. I just removed HttpSession from my application. It's really hard to keep sessions in sync when many

Jetty http session is always null (Embedded Container, ServletHolder)

时光毁灭记忆、已成空白 提交于 2020-01-01 08:56:27
问题 I am trying to implement a simple servlet which uses a HTTP session in an embedded jetty (7.3.0 v20110203) container. To start jetty I use the following code: Server server = new Server(12043); ServletContextHandler handler = new ServletContextHandler(ServletContextHandler.SESSIONS); handler.setContextPath("/"); server.setHandler(handler); ServletHolder holder = new ServletHolder(new BaseServlet()); handler.addServlet(holder, "/*"); server.start(); server.join(); The servlet acquires a

Xhtml pages and HttpSession test , no jstl?

一世执手 提交于 2020-01-01 07:16:12
问题 I have a dynamic web application in Java EE with JSF, Facelets, Richfaces. My pages are all xhtml pages. So JSTL isn't working in it. For my account pages and all other private pages to be reachable, I want to test if the user got connected, so if the attribute session in HttpSession is not null. If it's null, the user gets redirected in the welcome page. I tried in my xhtml page : <jstl:if test="${sessionScope['session']==null}"> <jstl redirect...> </jstl:if>--> but as it's not jsp page it

How to get the IP address when a session is created?

喜欢而已 提交于 2019-12-30 09:38:36
问题 In my grails application, I have implemented the interface HttpSessionListener to listen for session creation as given below: class MyHttpSessionListener implements HttpSessionListener { public void sessionCreated(HttpSessionEvent event) { log.info "***************** Session created: id= ${event.getSession()?.id}" } } Now, I would like to log the IP address that is responsible for the session creation . How can I do that? 回答1: you can access the RequestContextHolder and get the value String

HttpSessionListener.sessionCreated() not being called

折月煮酒 提交于 2019-12-29 08:18:15
问题 I have a very simple Servlet and a very simple 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