Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on Servlet Redirection

 
Senthil Somasundaram
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Amit KumarS
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sri Basavanahally
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sainudheen Mydeen
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 642
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Basavaraju Banakar
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic