0

I have implemented with a servlet with below doGet & doPost methods:

        public void doGet(HttpServletRequest request, HttpServletResponse response){
               // code      
            }

        public void doPost(HttpServletRequest request, HttpServletResponse response){
               // code      
            }

My question: Is the HttpServletRequest object in these methods unique for every unique ?

I am using request.setAttribute("att","value"); method. to save some values.

I want to know if I save an attribute in first request, will be it present in the next request object. (Provided both requests are received at almost same time)

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555

1 Answers1

1

No - its a new request every time - any attributes set in one request, will not be there when the next request comes in.

If you want to set attributes that are persistent across requests, you can use:

request.getServletContext().setAttribute("att","value");
Dharman
  • 30,962
  • 25
  • 85
  • 135
Tony Weston
  • 317
  • 2
  • 9
  • Thanks for the answer :), Just want to know -- even if there are multiple requests in a single second, this stays same right? I mean each request will have it's own saved attributes right? Thanks in advance!! – Runtime Terror - BS Dec 21 '20 at 12:02
  • Even if there are multiple concurrent requests arriving at the same moment and handled by different threads. They will all be unique, and all have their own set of attributes. – Tony Weston Dec 21 '20 at 12:05