Calling session on Grails Service


/ Published in: Groovy
Save to your folder(s)

how to call session from grails service (spring service)


Copy this code and paste it in your HTML
  1. /// for example in your controller you write : session.user = "wysmedia" ;
  2. /// you can retrive the value on grails service using this following way.
  3.  
  4. import javax.servlet.http.HttpSession
  5. import org.springframework.web.context.request.RequestContextHolder
  6.  
  7. class SessionStorageService {
  8.  
  9. static transactional = false
  10. static scope = "singleton"
  11.  
  12. def setUser(User user) {
  13. getSession().user = user
  14. }
  15.  
  16. def getUser() {
  17. getSession().user
  18. }
  19.  
  20. private HttpSession getSession() {
  21. return RequestContextHolder.currentRequestAttributes().getSession()
  22. }
  23. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.