Conditional Forward using EL
We can forward one page to another jsp page, html page or any other servlet page. A condition is checked before forwarding the page to another page.
In this example we are using two pages to fulfill this condition.
- ConditionalForwardUsingEL.html
- ConditionalForwardUsingEL.jsp
In the first page we are making a html form in which the user will enter his name and the password to enter into the page.
In the second page we are retrieving the values from the html page which we have have passed in the html page. In this jsp page we are checking the condition if the "username" is equal to null then the page will be forwarded back to the html page.
The code of the program is given below:
<html> <head> <title>This is Conditional Forward using EL</title> <body> <form method = "get" action = "ConditionalForwardUsingEL.jsp"> <b>Enter your name :<i nput type = "text" name = "username" ><b><br> <b>Enter the password : <input type = "password" name = "pwd" ><b><br> <input type = "submit" name = "submit" value = "submit"><b><br> <form> </body> <html> |
<html> <head> <title>Conditional Forward By using EL</title> </head> <body> <% if(request.getParameter("username")==null || request.getParameter("username").equals("")) {%> <jsp:forward page = "ConditionalForwardUsingEL.html"/> <%} else { %> Hello : ${param.username} ! How are you. <% } %> </body> </html> |
The output of the program is given below:
When the name is null:
When we entered the values:
The output will be: