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 8654087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:41:57+00:00 2026-06-12T14:41:57+00:00

hi.. stackoverflow team member. I am trying to use the HttpSession in java to

  • 0

hi.. stackoverflow team member.

I am trying to use the HttpSession in java to set some values like userid, so I can use the variable till the session remains present.

I am using spring3.0 for the request mapping. My login check code is given below

@RequestMapping(value = "/login/GetLoginCheck.action")
    public @ResponseBody
    Map<String, Object> loginCheck(HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        List<Employee> emplist = null;
        try {

            GlobalController.session = request.getSession();
            if (!GlobalController.session.isNew()) {
                this.setUsername(request.getParameter("username"));
                this.setPassword(request.getParameter("password"));

                emplist = loginservice.getEmployee(this.getUsername(),this.getPassword());

                if(emplist.size()>0)
                {
                    for(Employee employee: emplist)
                    {
                        this.setEmployeeid(employee.getId());

                        synchronized (GlobalController.session) {
                              GlobalController.session.setAttribute("userid", employee.getId());
                            }
                    }

                }else
                {
                    return getModelMapError("The username or password you entered is incorrect.");
                }



            }else{
                System.out.println("already session created");
                System.out.println("SESSION ID ::"+GlobalController.session.getId());
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

        logingview = this.loginView(this.getUsername(),this.getPassword());
        return getMapUser(emplist,logingview);
    }

and my GlobalController class code is given below

public class GlobalController implements HttpSessionListener{


    private static int totalActiveSessions = 0;
    public static HttpSession session = null;

    @Override
    public void sessionCreated(HttpSessionEvent event) {
        // TODO Auto-generated method stub
        synchronized (this) {
            totalActiveSessions++;
        }
        System.out.println("Session Created: " + event.getSession().getId());
        System.out.println("Total Sessions: " + totalActiveSessions);

    }
    @Override
    public void sessionDestroyed(HttpSessionEvent event) {
        // TODO Auto-generated method stub
        synchronized (this) {
            totalActiveSessions--;
        }
        System.out.println("Session Destroyed: " + event.getSession().getId());
        System.out.println("Total Sessions: " + totalActiveSessions);
    }


}

As the user Login my “/login/GetLoginCheck.action” executes and with this I am setting the attribute empoyeeId: 2 to the session.

But I open the same url in another pc in lan and login with another user named having empoyeeId: 1.

The problem I am having is that when I see the log or open the gridpanel having the employeeId:1 it shows me the data belonging to the employeeId:2.

Also the sessionId get override with the newly logged user session.

Please suggest me some way I can try to implement session in a proper way, so I get the data and session belonging to the intended employee only.

  • 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-12T14:41:58+00:00Added an answer on June 12, 2026 at 2:41 pm

    Thanks so much for your replies. I am able to solve my problem with making session as class variable.
    below is the code I tried to make the session working in my application in the loginCheck method.

    HttpSession session;
    session = request.getSession();
    session.setAttribute("employeeid", this.getEmployeeid());
    

    and to retrieve the session attribute done with below code

    session = request.getSession();
    System.out.println("EMPLOYEE ID ::"+session.getAttribute("employeeid"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Today, a fellow team member checked-in some code that looked like this var query
stackoverflow forum member I am having some problem with a certain report designed using
Many applications (like StackOverflow) has been written by three developers (a small team), would
stackoverflow team member I am having problem with displaying the json subarray data to
First, thanks for the StackOverflow team, cause it's a very useful website, since i'm
I am aware of this question: https://stackoverflow.com/questions/428691/how-to-encourage-implementation-of-tdd In my team, we write a lot
I am looking to set up an internal wiki for our development/design team. The
Hi stackoverflow team i have a problem in converting base64 string to bitmap in
I am presenting Git to a 10 man programming team who currently use Visual
Stackoverflow community. I found out that WSO2 community can be contacted on this site,

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.