Win a copy of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Bear Bibeault
  • Liutauras Vilda
  • Devaka Cooray
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

How does a cookie object work when the request is forwarded to another servlet ?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider the code... I got the request parameters using request.getParameter() method and created a cookie object based on the  request parameter and added the cookie object to response object.
My question is, when I forwarded the request to another servlet, isn't the response objects buffer deleted and a new response object is forwarded along with the request object ?? So, i'm guessing the cookie added to response object is also deleted. so, how all this works ??




When I click on login button the LoginServlet gets invoked.



Consider there is another servlet "ForwardServlet" to which the request is being forwarded.
 
Marshal
Posts: 67357
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What makes you think the response is deleted upon a forward?
 
Saarya Mohapatra
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose I added a response to the response object before forwarding to another servlet..

out.println("Forwarding the request to another servlet ");
response.addCookie(cookie);

RequestDispatcher rd = request.getRequestDispatcher("forward");
rd.forward(request,response);

So, when a response is given back to client from the second servlet I don't see the output saying "Forwarding the request to another servlet" along the responses which the second servlet generates
 
Bear Bibeault
Marshal
Posts: 67357
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Research what out.println() does.

Hint: it does not add output to the response.
 
Saarya Mohapatra
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please elaborate the answer. I tried researching about what actually is happening but couldn't. My head is exploding!!!
 
When evil is afoot and you don't have any arms you gotta be hip and do the legwork, but always kick some ... tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!