| Author |
Question on Servlet Redirection
|
Senthil Somasundaram
Greenhorn
Joined: Jun 30, 2003
Posts: 17
|
|
Hi , Pls Clear my Following Doubts.. 1. When We use RequestDispatcher to redirect a request some other Page Which Method(GET Or POST Or Depend upon the previous Request)It will Use.... 2. Can We call Destroy method inside the Service Method in Servlet 3. What is the Difference Between redirectURL() and RequstDispatcher in redirecting the page Thank u Cheers, Sen
|
 |
Amit KumarS
Ranch Hand
Joined: Oct 10, 2003
Posts: 100
|
|
hi..
1. When We use RequestDispatcher to redirect a request some other Page Which Method(GET Or POST Or Depend upon the previous Request)It will Use....
answer to this is the thrid option.. it will be processed according to the original request sent by the client.
2. Can We call Destroy method inside the Service Method in Servlet
for this.. i don't think we can call destroy() inside service().. destroy is supposed to be called by the client...
3. What is the Difference Between redirectURL() and RequstDispatcher in redirecting the page
here i want to ask whther any method redirectURL() exists... if it exists then i am sorry i am not aware of it (please let me know in which class or interface does it exist!!).. what i know is there are two ways of redirecting the servlet.. 1. response.sendRedirect() 2. request.getRequestDispatcher().forward(request, response); the difference between two is that.. in first method.. the response is commited to client and then the client is forced to call the URL mentioned as the parameter.. but in second case.. the request is forwarded as it is came to another servlet .. so the extra round to client is saved.. but using the first method u can call any URL of another server, which is not possible in second case.. the RequestDispatcher has to have a relative or excat URL of same server on which the redirecting servlet resides. i think this should be clear... correct me if i am wrong... Thanks Amit
|
****************************<br />In 24 hrs Earth rotates once on its Axis.
|
 |
Amit KumarS
Ranch Hand
Joined: Oct 10, 2003
Posts: 100
|
|
oops .. i made a mistake in second question.. destroy is not called by client.. it is called by container... rest is same.. thanks Amit
|
 |
Pradeep bhatt
Ranch Hand
Joined: Feb 27, 2002
Posts: 8876
|
|
Can We call Destroy method inside the Service Method in Servlet
Yes you can but it is supposed to be called by the web container.
|
Groovy
|
 |
Sri Basavanahally
Ranch Hand
Joined: Oct 07, 2003
Posts: 75
|
|
THe destroy() method on a Servlet will not be called by the container until the service method(s) for the servelt have finished executing. -Sri
|
UP THE IRONS !
|
 |
Sainudheen Mydeen
Ranch Hand
Joined: Aug 18, 2003
Posts: 218
|
|
Why does someone want to call destroy method inside service method? In this method the servlet should cleanup resources which is acquired in the earlier part of its lifecycle. Once this method is called by the container, the servlet instance will be out of service and the container will never call service method of that particular instance. I think there must be certain rule in calling this method. Any idea? -Sainudheen
|
 |
nick zhao
Greenhorn
Joined: Oct 10, 2003
Posts: 3
|
|
The question about destroy() when will be invoked by the servlet container is really a question about servlet lifecyle. To understand invoking destroy() by the servlet container you have to know the conditions which a servlet will be destroyed. Refering SRV2.3 in servlet specification2.4 might give you some useful imformation. Condition 1: The servlet container is being shutdown. Condition 2: The servlet container wants to conserv memory resource. (These two are referenced @ SRV2.3.4) Condition 3: The service method throws a UnavailabelException, the servlet container must release the servlet with invoking destroy method. (In general, the exception should be 'permanent' type, I bet there are servlet container implementations did same work as permanent when a temorary is UnavailableException throwed). Condition 4: I think there might be some other cases will invoking destroy, that depends on the implementations of servlet container. Am i right? Corrects me, you have my appreciation.
|
 |
Praful Thakare
Ranch Hand
Joined: Feb 10, 2001
Posts: 613
|
|
Hi, According to me Ans to Senthils first question is option 2( Get method). It has nothing to do with previous request. Correct me if I m wrong  [ October 15, 2003: Message edited by: Praful Thakare ]
|
All desirable things in life are either illegal, banned, expensive or married to someone else !!!
|
 |
Basavaraju Banakar
Greenhorn
Joined: Jul 18, 2002
Posts: 25
|
|
life-cycle methods and the sequence in which they are called: 1. The servlet is constructed, then initialized with the init method. 2. Any calls from clients to the service method are handled. 3. The servlet is taken out of service, then destroyed with the destroy method, then garbage collected and finalized
|
It is impossible to make anything foolproof because fools are so ingenious..Murphy<br />Basu.
|
 |
 |
|
|
subject: Question on Servlet Redirection
|
|
|