sendRedirect() Example Servlets – Send HTML form to Client

sendRedirect() Example Servlets – Send HTML form to Client


It is the modification of the first program Login Validation. The modification is instead of sending INVALID message, a new HTML form is sent to the user wherein the user can fill up again and send. This HTML form is existing already on the server. It is not created on the fly. That is why, I called it as a static form.

Example on sendRedirect() Method

Client Program: File Name: UserPass.html

Servlet Program: File Name: Validation.java

res.sendRedirect("UserPass.html");

sendRedirect(String) is a method of HttpServletResponse which is capable of sending a file to the client passed as a string parameter.

Following is the method signature as defined HttpServletResponse interface.

public abstract void sendRedirect(java.lang.String) throws java.io.IOException;

Note: sendRedirect() is not a method of ServletResponse.

When user name and password are given correct

ima

the response screen is

sendRedirect()

When the password is given wrong as hereunder,

sendRedirect()

the following fresh (new) form is sent.

sendRedirect()

Leave a Reply

Your email address will not be published. Required fields are marked *