This is one of the most frequently asked Java interview questions, so it is important to prepare for it thoroughly.
One of the most frequently asked Servlet interview questions is the difference between sendRedirect() and forward(). Although both are used to transfer a request from one resource to another, they work in different ways.
How
forward() Works The forward() method forwards the request from one resource (Servlet, JSP, or HTML) to another within the same web application. The control is transferred internally by the server, so the client (browser) is unaware of the forwarding.
Example
RequestDispatcher dispatcher = request.getRequestDispatcher("home.jsp");
dispatcher.forward(request, response);
Key Points
- The browser URL remains the same.
- Uses the same request and response objects.
- Request attributes are preserved.
- Faster because no additional request is sent to the server.
Hi there, yup this piece of writing is truly good and I have learned lot of things from it concerning blogging.
ReplyDeletethanks.