Request Dispatcher
Request Dispatcher
ServletConfig interface
ServletContext ServletConfig
Available to all servlets and JSPs that are part Available to only servlet for which the
of Web app <init-param> was configured.
Parameters are initialized with in <web-app> Parameters are initialized with in <servlet> for
not within <servlet> each specific servlet
Important Methods of ServletContext
The forward() method works at server side. The sendRedirect() method works at client
side.
It sends the same request and response It always sends a new request.
objects to another servlet.
It can work within the server only. It can be used within and outside the
server.
Example: Example:
request.getRequestDispacher("servlet2").for response.sendRedirect("servlet2");
ward(request,response);
Syntax of sendRedirect() method
Syntax:
public void sendRedirect(String URL)throws IOException;
Example:
response.sendRedirect("https://www.google.com");