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

  • Home
  • SEARCH
  • 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 7752589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:50:18+00:00 2026-06-01T11:50:18+00:00

General question about java servlets and the best way to handle requests. If I

  • 0

General question about java servlets and the best way to handle requests. If I hit my doGet method from a remote server request:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
  ....
  <do work here>
  ....
  kill(request);
}

private void kill(HttpServletRequest request) {
//How do I kill the user session here?
}

After I process the request at my end and generate my output to the requester, I want to basically “kill” their session. Currently, that session lingers and thus eats up memory. Then once the max is reached, all other calls are timed out.

I tried creating a HttpSession object using the request object, but got the same results:

HttpSession session = request.getSession();
session.invalidate();
  • 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-01T11:50:19+00:00Added an answer on June 1, 2026 at 11:50 am
    HttpSession session = request.getSession(false);
    if (session != null) {
        session.invalidate();
    }
    

    is the proper way to go as suggested by the documentation. A new session will be created once the client sends a new request.

    You mentioned that your sessions still take up memory. Do you have any other references to those objects on the session?

    You also might want to have a look at: Servlet Session behavior and Session.invalidate

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

Sidebar

Related Questions

This question is about 64-bit Java apps in general, although I came upon it
Just a general question about what the best practice is: public void Foo() {
I have a general question about the way that database indexing works, particularly in
i have a general question about how sql server evaluates the joins.The query is
I have a quite general question about java and regular expression. If we lock
I'm new to Java and have a question about a warning: My general code:
Ok this is a general question about how to solve this issue, not to
This is a general question about MVC as a pattern, but in this case
Yesterday I asked this general question about decimals and their internal precisions. Here is
just had a general question about how to approach a certain problem I'm facing.

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.