A RequestDispatcher is an object which receives the request from the client and sends (forward or include) the request to any resource ( a servlet, jsp or html).
RequestDispatcher is an interface available as part of javax.servlet package. A servlet container will creates the RequestDispatcher object.
As RequestDispatcher is an interface, it can't directly create the object . Container will creates the object to it's (RequestDispatcher) implementation class.
The class name will differ from server to server as every server should implement servlet api they chose proprietay names to the implementation classes.
Incase of Tomcat the implementation class to RequestDispatcher is ApplicationDispatcher . you can get more information from here.
Once we got RequestDispatcher object we can perform two operations.
forward (request, response) and
include (request, response).
Getting RequestDispatcher object:
There are mainly three ways to get the RequestDispatcher object created by the servlet container.
1. Using ServletContext.getRequestDispatcher("/path"):
Once we have ServletContext object we can get the RequestDispatcher object by using context.getrequestDispatcher("/path"). where path is the absolute path of the resource to which we want to send the request.
Here is the example.
RequestDServlet is the one which will send request to another resource.
in above servlet,' /requestR ' is the absolute path of the resource (RequestRServlet) to which request has to be sent.
forward(request, response) will through ServletException,IOException. That's why we have placed that code in try catch block.
RequestRServlet is the servlet which will receive request from RequestDServlet with the help of RequestDispatcher.
Configure both servlets in web.xml
If we run the application , we will get output showing text "Request Dispatcher Dispacthed the REQUEST" as the request is forwarded to RequestRServlet.
We can perform include() operation too , will be discussed in next way of getting RequestDispatcher.
2. ServletContext.getNamedDispatcher("name"):
This is another way of getting RequestDispatcher if we have ServletContext object.
The only change we need to do is in RequestDServlet .
getNamedDispatcher("name") will accept name of resource to which request has to be sent.
include(request, response) will include the contents of both resources and display to the client.
3. ServletRequest.getRequestDispatcher("path"):
If we have a request object, we can get the RequestDispatcher object from
request.getRequestDispatcher("path"), where path refers to absolute or relative path of the resource to which request has to be sent.
Again, the change only we need to do in RequestDServlet.
Here, two types of paths we can give to the request.getRequestDispatcher().
If we give '/path' it will be considered as absolute path and if we mention "path" it will be treated as relative path.
Absolute path and Relative path :
Absolute path is the exact path showing the location of resource where it is available.
example:' /ServletApp/requestR ' or ' /requestR'
Server will get's the context path (/ServletApp) and appends the path (/requestR) to it.
Relative path is the path relative to the current path of the resource.
example: ' requestR '
Server will get's the current path of the resource executing, i.e,(/ServletApp/requestD) and get's the context path from that (/ServletApp/) by removing resource path (requestD) . Finally it will append the resource to which request has to be sent (requestR).
Note:
We can use any resource (html, jsp, servlet) to forward or include the request with RequestDispatcher.
Note:
We can use any resource (html, jsp, servlet) to forward or include the request with RequestDispatcher.
ReplyDeleteAfter reading this web site I am very satisfied simply because this site is providing comprehensive knowledge for you to audience.
Thank you to the perform as well as discuss anything incredibly important in my opinion. We loose time waiting for your next article writing in addition to I beg one to get back to pay a visit to our website in
selenium training in Bangalore
selenium training in Marathahalli
selenium training in Btm layout
selenium training in Jaya nagar
selenium training in Electronic city
selenium training in Kalyan nagar
This looks absolutely perfect. All these tiny details are made with lot of background knowledge. I like it a lot.
ReplyDeletePython Online training
python Course institute in Chennai
Python Course institute in Bangalore
Wonderful to visit your websites, This sites are fully filled with full of Information's. I perceived a lots of knowledge from this Articles.
ReplyDeleteFor more to learn about Python Visit below
python training in chennai | python training in annanagar | python training in omr | python training in porur | python training in tambaram | python training in velachery
I really enjoy simply reading all of your weblogs. Simply wanted to inform you that you have people like me who appreciate your work. Definitely a great post I would like to read this DevOps Training | Certification in Chennai | DevOps Training | Certification in anna nagar | DevOps Training | Certification in omr | DevOps Training | Certification in porur | DevOps Training | Certification in tambaram | DevOps Training | Certification in velachery
ReplyDeletehatay evden eve nakliyat
ReplyDeleteısparta evden eve nakliyat
erzincan evden eve nakliyat
muğla evden eve nakliyat
karaman evden eve nakliyat
GSF2U
urfa evden eve nakliyat
ReplyDeletemalatya evden eve nakliyat
burdur evden eve nakliyat
kırıkkale evden eve nakliyat
kars evden eve nakliyat
386T
F779F
ReplyDeleteUşak Parça Eşya Taşıma
Lovely Coin Hangi Borsada
Yalova Evden Eve Nakliyat
Gümüşhane Lojistik
Erzincan Şehirler Arası Nakliyat
Amasya Parça Eşya Taşıma
Ankara Parça Eşya Taşıma
Hamster Coin Hangi Borsada
Mardin Evden Eve Nakliyat
9AE3E
ReplyDeleteEdirne Şehir İçi Nakliyat
Çankırı Evden Eve Nakliyat
Çerkezköy Petek Temizleme
Konya Şehir İçi Nakliyat
Hexa Coin Hangi Borsada
Kayseri Lojistik
Kars Şehirler Arası Nakliyat
Kars Parça Eşya Taşıma
Malatya Evden Eve Nakliyat
A7EB8
ReplyDeleteMardin Evden Eve Nakliyat
Artvin Şehirler Arası Nakliyat
Tekirdağ Çatı Ustası
Afyon Şehir İçi Nakliyat
Malatya Lojistik
Rize Lojistik
Düzce Parça Eşya Taşıma
Kırklareli Parça Eşya Taşıma
Denizli Evden Eve Nakliyat
9D9FD
ReplyDeleteÇerkezköy Korkuluk
Gölbaşı Fayans Ustası
Ünye Çatı Ustası
Malatya Evden Eve Nakliyat
Bolu Evden Eve Nakliyat
Antep Evden Eve Nakliyat
Hatay Evden Eve Nakliyat
Karapürçek Boya Ustası
Altındağ Parke Ustası
2AE45
ReplyDeletebinance referans kodu
referans kimliği nedir
binance referans kodu
binance referans kodu
binance referans kodu
referans kimliği nedir
resimli magnet
resimli magnet
resimli magnet
A237B
ReplyDeletereferans kimliği nedir
binance referans kodu
binance referans kodu
binance referans kodu
resimli magnet
binance referans kodu
referans kimliği nedir
resimli magnet
resimli magnet
1F600
ReplyDeletebitrue
bingx
canlı sohbet ucretsiz
bitcoin hesabı nasıl açılır
coinex
kripto para nasıl alınır
kaldıraç nasıl yapılır
probit
binance
1013D
ReplyDeletecanlı sohbet
probit
filtre kağıdı
kaldıraç nasıl yapılır
https://kapinagelsin.com.tr/
binance referans kimliği
telegram kripto para
referans kodu
bitexen
9E132
ReplyDeletemobil 4g proxy
kraken
bitcoin ne zaman yükselir
4g mobil
kripto para haram mı
kizlarla canli sohbet
binance referans kimliği nedir
bitcoin giriş
bybit
شركة رش حشرات بالاحساء UM2uUCOr14
ReplyDelete