Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Jsp Simple-jsp-example Conditional Forward using EL

Related Tutorials


 
 

Share on Google+Share on Google+

Conditional Forward using EL

Advertisement
We can forward one page to another jsp page, html page or any other servlet page.

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.

  1. ConditionalForwardUsingEL.html
  2. 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:


Download this example.
 

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 11, 2008

Related Tutorials

Discuss: Conditional Forward using EL  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com