How does Session handling works in Servlet environment

Carvia Tech | December 04, 2019 | 1 min read | 3 views


There are multiple ways to handle session by a servlet framework. For example following methods can be used,

  1. Storing Cookies on the client side

  2. URL Rewriting

  3. Hidden form fields

Servlets use cookies as the default mechanism for session tracking, but in case cookies are disabled on the client, Server can use URL re-writing for achieving the same.

When server calls request.getSession(true), then server generates and sends JSESSIONID back to the client for all future session references. JSESSIONID will then be stored by the client and sent back to the server using any of the above mentioned mechanisms.

To ensure that your Servlets support servers that use URL rewriting to track sessions, you must pass all the URL’s used in your servlet through the HttpServletResponse.encodeURL() method


Top articles in this category:
  1. Feign exception handling in Spring Cloud
  2. How will you handle unresolved circular dependency in spring dependency injection?
  3. How to implement thread safe table backed global counter in spring hibernate?
  4. How to prevent duplicate form submission in Spring MVC
  5. Disable SSL certificate validation in RestTemplate
  6. What is N+1 problem in Hibernate, how will you identify and solve it?
  7. File Upload in Spring MVC using RestTemplate with ByteArrayResource & FileSystemResource


Find more on this topic:
Spring Framework image
Spring Framework

Spring Framework - MVC, Dependency Injection, Spring Hibernate, Spring Data JPA, Spring Boot and Spring Cloud for Microservices Architecture.

Last updated 1 week ago


Recommended books for interview preparation:

This website uses cookies to ensure you get the best experience on our website. more info