Issue
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)
Solution
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");
Answered By - Tony Weston
Answer Checked By - Terry (JavaFixing Volunteer)