Servlet 03

793 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
793
On SlideShare
0
From Embeds
0
Number of Embeds
9
Actions
Shares
0
Downloads
17
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Servlet 03

  1. 1. <ul><li>Objectives </li></ul><ul><li>In this lesson, you will learn to: </li></ul><ul><li>Implement inter-servlet communication </li></ul>
  2. 2. <ul><li>Inter-Servlet Communication </li></ul><ul><li>Allows servlets that are executing on the same Web server to: </li></ul><ul><ul><li>Communicate with each other </li></ul></ul><ul><ul><li>Share resources amongst each other </li></ul></ul>
  3. 3. <ul><li>The RequestDispatcher interface can be used to invoke a servlet from the other </li></ul>
  4. 4. <ul><li>RequestDispatcher </li></ul><ul><li>Can be used to delegate a request to other resources that are existing on the Web server, such as a: </li></ul><ul><ul><ul><li>HTML page </li></ul></ul></ul><ul><ul><ul><li>Servlet </li></ul></ul></ul><ul><ul><ul><li>JSP page </li></ul></ul></ul>
  5. 5. <ul><li>RequestDispatcher </li></ul><ul><ul><li>Encapsulates the URL of a resource that exists in a particular servlet context . </li></ul></ul>
  6. 6. <ul><li>Inter-Servlet Communication (Contd.) </li></ul><ul><li>The following are few methods that can be used for communication between servlets </li></ul>
  7. 7. This method belongs to the interface javax.servlet.ServletConfig public abstract ServletContext getServletContext() This function returns the context of the servlet. getServletContext() Description Method name
  8. 8. public abstract RequestDispatcher getRequestDispatcher(String urlpath) This method is used to get a reference to a servlet through an URL that is specified as the parameter. The dispatcher that is returned is used to invoke the servlet. If a dispatcher cannot be obtained for the URL specified, this function returns a null. getRequestDispatcher() Description Method name
  9. 9. public abstract void forward(ServletRequest request,ServletResponse response) throws ServletException, IOException This method belongs to the RequestDispatcher interface and can be used to forward a request from one servlet to another. This method must be used when the output is completely generated by the second servlet or the servlet that is invoked. forward() Description Method name
  10. 10. public abstract void include(ServletRequest request,ServletResponse response) throws ServletException, IOException This function is also used to invoke one servlet from another like the forward() function. However, you can also include the output of the first servlet with the current output. include() Description Method name
  11. 11. <ul><li>Summary </li></ul><ul><li>In this lesson, you learned that: </li></ul><ul><li>RequestDispatcher interface can be used to call one servlet from the other </li></ul>
  12. 12. <ul><li>The forward() and the include() method can be used to invoke one servlet from the other </li></ul><ul><li>The data, which is common to servlets can be accessed by using the ServletContext interface. </li></ul>

×