sendRedirect JSP Example

In the example, client sends user name to login (no password for simplicity). Server validates and sends back result of validation. If user name is successful, sends message "Login is Success" and fails sends a new login form to client to enter a new user name and repeat the process until login is successful. To send the new HTML login form to client, the JSP uses response.sendRedirect() method.

Example on sendRedirect JSP

Client-side HTML File Name: Login.html


Login User Name

Enter User Name
Click to Validate

Server-side JSP File Name: SendForm.jsp

    String userName = request.getParameter("t1");   

Login is Success

"); } else { response.sendRedirect("Login.html"); } %>

Screenshot of client Login.html form when some user name is entered.


Response of server when validation is successful.

sendRedirect JSP

Response to client of sending a fresh Login form. Observe the fresh (empty) form.

sendRedirect JSP


sendRedirect() is a method of response object. We know earlier response object is one of the 9 implicit objects, JSP supports and also we know response object is an instance of HttpServletResponse. That is other way to say, sendRedirect() is a method of HttpServletResponse interface.

Pass your comments and suggestions to improve the quality of this tutorial "sendRedirect JSP Example".

1 thought on “sendRedirect JSP Example”

Leave a Comment

Your email address will not be published.