Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8199053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:05:35+00:00 2026-06-07T06:05:35+00:00

I have a question that will probably have a very simple solution. I’m running

  • 0

I have a question that will probably have a very simple solution. I’m running grails 1.3.7 and I’m trying to set a session variable like: session["username"] = uName where uName is a value returned from a database query.

The problem I’m having is that the keyword session seems to be not recognized by grails (it’s underlined). Further, when I actually try to run the app I get this error: No such property: session for class:.

I don’t have any imports, should I?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T06:05:37+00:00Added an answer on June 7, 2026 at 6:05 am

    You only have the session variable available to you in controllers, taglibs and GSPs, not in services or domain classes. You can always access it via the thread-local holder, but bear in mind that you only have a session if the current thread is a request handler (i.e. not if it’s a background thread):

    import org.springframework.web.context.request.RequestContextHolder
    
    def currentRequest = RequestContextHolder.requestAttributes
    if(currentRequest) { // we have been called from a web request processing thread
      // currentRequest is an instance of GrailsWebRequest
      currentRequest.session["uName"] = ...
    } else {
      // not in a request handler thread, so no session available
    }
    

    but it’s generally better to keep logic that requires access to the HTTP request in controllers (or taglibs) where you know that you will always have a “current request”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My question is probably very simple but it could also be the case that
I have a simple question that I am posing mostly for my curiousity. What
Probably very simple question (I just want to ensure I'm right). Title is not
This is a very simple, probably too simple question but I'm afraid my limited
I have what is probably a simple question here about Castle Windsor, which I
This is probably a very generic question but I will shoot anyway since I
Okay, this is probably very simple but, I have the below checks (not at
This is probably a very simple question for you SQL folks out there. I
I'm aware that there probably isn't a perfect solution to my question (this sounds
This is probably a very simple question to answer. i am new to Rails

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.