Posted By

callmeblessed on 01/02/09


Tagged

java groovy grails spring


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

sfhynx


Calling session on Grails Service


 / Published in: Groovy
 

how to call session from grails service (spring service)

  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  

You need to login to post a comment.