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.
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:

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Conditional Forward using EL
Post your Comment