Grails Service 获取session,response,request,servletContext

原文:http://blog.csdn.net/a__java___a/article/details/7755359


import org.codehaus.groovy.grails.web.util.WebUtils
import org.springframework.web.context.request.RequestContextHolder
……
//Getting the Request object
def getRequest(){
    def webUtils = WebUtils.retrieveGrailsWebRequest()
    webUtils.getCurrentRequest()
}
//Getting the Response object
def getResponse(){
    def webUtils = WebUtils.retrieveGrailsWebRequest()
    webUtils.getCurrentResponse()
}
//Getting the ServletContext object
def getServletContext(){
    def webUtils = WebUtils.retrieveGrailsWebRequest()
    webUtils.getServletContext()
}
//Getting the Session object
def getSession(){
    RequestContextHolder.currentRequestAttributes().getSession()
}


你可能感兴趣的:(request)