This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
forward action in your JSP is converted into a RequestDispatcher.forward() in the translated servlet. sendRedirect and RequestDispatcher.forward() are different in the following ways:
Send redirect sends the response to the client with redirect header(i dont know the exact name) which has information about which url to resend request to, to get the actual response. So it involves a round trip. client request->send redicret response->client resends request->response.
Forward, on the other hand, handles the forwarding of the request entirely on the server side. The client doesnt even come to know that the reponse was generated by some resource other than the one it had asked the response from.
So, the URL in the browser's address bar changes in case of sendRedirect but doesnt change in case of forward.
Since sendRedirect forces the client to send a new request to the specified url, you cannot share request scope attributes between servlets if you are using sendRedirect. In case of foward, the request object remains the same which allows u to set some attributes in the request before forwarding it and retrieve them in the forwarded servlet/jsp.
The RequestDispatcher's forward method and the jsp:forward action are both server-centric. Specifically, your request is forwarded to the target resource on the server without notifying the client first. Thus, a single request requires only a single round trip between client and server. In contrast, the sendRedirect method sends a message back to the client instructing it to request the target resource. Thus, a single request requires two round trips between the client and server to get the final target resource. Bob Kerfoot