How does Session handling works in Servlet environment

Upasana | December 04, 2019 | 1 min read | 79 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 to prevent duplicate form submission in Spring MVC
  3. Prevent Lost Updates in Database Transaction using Spring Hibernate
  4. Synechron Java Interview Questions
  5. Disable SSL validation in Spring RestTemplate
  6. Feign Client Logging and connection timeout
  7. Table backed global counter in spring hibernate

Recommended books for interview preparation:

Find more on this topic:
Buy interview books

Java & Microservices interview refresher for experienced developers.