The difference is an extra trip to the browser.

res.sendRedirect does a redirect thru the browser (using the Location: HTTP
header).

RequestDispatcher.forward directly calls the doGet method of the requested
servlet.

So, RequestDispatcher is more efficient.

Rick L Sample wrote:

> What is the difference between using:
>
> ...
>     if (session == null) {
>       res.sendRedirect("http://localhost:8080/error.html");
>     }
> ...
>
> as opposed to:
>
> ...
>       String url="/jsp/shopping/EShop.jsp";
>       ServletContext sc = getServletContext();
>       RequestDispatcher rd = sc.getRequestDispatcher(url);
>       rd.forward(req, res);
> ...
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to