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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:24:23+00:00 2026-06-07T07:24:23+00:00

I am new to Java EE. I have a site which requires a user

  • 0

I am new to Java EE. I have a site which requires a user to log in, and after the user logs in I would like the user to see his/her own item (e.g: shopping cart).

So that means I have to use a session to accomplish that. But how do I deal with multiple sessions?

For example multiple users login to the system as well as to the same servlet? However, can I keep multiple sessions in one servlet? Do I keep a record of each of them? How does it work?

Can someone give an example please ?

  • 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-07T07:24:25+00:00Added an answer on June 7, 2026 at 7:24 am

    In servlet you have access to HttpServletRequest which provides you with a getSession() method. This methods returns session object (essentialy a key-value map), different for each user.

    If you put something into that map (like shopping cart), you can retrieve it later – but only when the same user accesses the application again (not necessarily the same servlet).

    public void doGet(HttpServletRequest request, HttpServletResponse response)
          throws IOException, ServletException {
    
        HttpSession session = request.getSession();
        session.getAttribute("cart");
        //...
        session.setAttribute("cart", whateverYouWant);
    

    Sessions are maintained in the servlet container and looked up by session id (typically a cookie). You don’t have to implement anything yourself.

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

Sidebar

Related Questions

I have a Java project which I'd like to convert to C#, and after
Like lots of askers on SO, I'm relatively new to java and have attempted
I want to access some pages of web site https://myoffice.bt.com which requires user authentication
I am new to Java. I just read that class variables in Java have
I'm new to Java and have gotten myself into a situation where it's evident
I am new in Java and have got as a task to find out,
Forgive me, I'm new to Java and have an extremely basic question. I have
Completely new to java and I have been playing around with regex in a
I am new to java and I have some problem on Casting. I have
I'm new to Java EE and have been struggling with some basic middleware concepts

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.