• +91 9723535972
  • info@interviewmaterial.com

Servlet Interview Questions and Answers

Question -
What is the difference between sendRedirect() and Forward() in a Servlet?



Answer -

The difference between sendRedirect() and Forward() can be explained as follows:

sendRedirect():

  • sendRedirect() method is declared in HttpServletResponse Interface.
  • The syntax for the function is as follows:
1  void sendRedirect(String URL)
  • This method redirects the client request for further processing, the new location is available on a different server or different context. The web container handles this and transfers the request using the browser, this request is visible in the browser in the form of a new request. It is also called a client-side redirect.
Forward():

  • Forward() method is declared in the RequestDispatcher Interface.
  • The syntax for the function is as follows:
forward(ServletRequest request, ServletResponse response)
  • This passes the request to another resource for processing within the same server, another resource could be any servlet, JSP page. Web container handles the Forward() method. When we call Forward() method, a request is sent to another resource without informing the client, about the resource that will handle the request. It will be mentioned on the requestDispatcher object which we can be got in two ways. Either using ServletContext or Request. 

Comment(S)

Show all Coment

Leave a Comment




NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners