Loading
forward VS sendRedirect

Java Quick Notes

Refresh Your Java - Before Java Interview

We are Agile, believe in less Documentation - Only Quick notes (Java Interview Questions) of Java/J2ee Read more....


Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet

Go to SiteMap

Q)  RequestDispatcher.forward() VS Response.sendRedirect () ?


Ans)

Since forward() method of RequestDispatcher is handled on the server , therefore the request and its associated session are
available to the forwarded resource
and you can pass data between them using request.setAttribute(). forward() separates the
responsibilities for handling the requests among several components. This method generally sends a request and response
object to resources (servlets or JSP's) of the same ServletContext.
RequestDispatcher.forward() and PageContext.forward() are effectively the same

       RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/web/tes.jsp");
       dispatcher.forward(req, resp);

sendRedirect() method of a response object sends the url  to the browser that includes the parameter of sendRedirect()
method Browser treats this a new request from the client. sendRedirect() forwards a requests to a resource outside of the
current web application. Using sendRedirect is similar to open a new browser and type your url. A sendRedirect() also updates
the browser history and transfers control only when the whole service method completes. There is only one way to pass data is
through the session or using web parameters (url?name=value).

  resp.sendRedirect(""/web/tes.jsp");      // Considered as new Request in the browser



Back to top

------------------------- We hope you got necessary Info On -----------------------------------------

forward VS sendRedirect


forward VS sendRedirect

-------------------------------------------------------------------------------------------------------



Face Book
Request for a Mock Interview/Training

Get a PDF

Face Book
Same look (Read) on any device, this is Ads free