Calling session on Grails Service

Calling session on Grails Service

 / Published in:  Groovy
  

how to call session from grails service (spring service)

Expand | Embed | Plain Text
   
   
    
    
    
    
  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. }

你可能感兴趣的:(Calling session on Grails Service)