Question

Whenever a request is send to a server,it forwards to the respective servlet.My question is till what time the attributes and parameter are there in the request scope?

  1. If we forward the request Why is the parameter still present?
  2. At what time we can say that request has been processed?
Was it helpful?

Solution

You seem to be a little confused about what a forward actually is. Compare it to the sending of an email. Lets assume you are named ServletA and I am named ServletB.

A client sends you an email, so they send that email to ServletA. The mail server receives the data and puts it as an email in your inbox. You read it and you think "nah, this email is not for me. ServletB needs to handle this". What do you do? forward the email to me, complete with all the content in that email. The alternative would have been that you would have sent me a new email with a copy of the text, but then you would lose the fact that the email is from the client; it would become a new email from you to me. When you forward the original email, the email stays sent by the client. I chose to reply, and I then reply to the client, not to you. You are no longer involved in the emailing process.

Now translating that story back to "request VS forward":

A browser sends a HTTP request (email) to a particular url; your server maps that URL to ServletA, so it gets to handle the request (receives the email in his inbox). But inside the code of ServletA it is determined that ServletB needs to handle it (reply to it), so the request (email) is forwarded to ServletB. At this point ServletB generates the response (reply), which will be sent back to the client. ServletA is no longer involved in the handling of this request.

As to when the request is processed: that would be when the response is fully sent to the client. Then the HTTP request cycle is done.

I hope that made things a bit more clear.

OTHER TIPS

It depends on various factors , actually we cant say how long the scope is available, because the container holds the request object , and that request object might be used in other context or may be in other servlet so which is not a fortunate thing to determine.

  • The only one case the request scope will get erase is on server stop
  • There is also on other case when the destroy method gets called
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top