Home Jstl Using tag of Core JSTL tags
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Using tag of Core JSTL tags

Advertisement
In this example we have used Core JSTL tag that is used to redirect the page to given url, here param is used to get parameter from request.

Using tag <c:redirect> of Core JSTL tags

     

In this example we have used Core JSTL tag <c:redirect> that is used to redirect the page to given url, here param is used to get parameter from request. Tag <c:forEach> is member of Core tag library of JSTL so before using Core JSTL tags we must include following line of code :-

  <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

redirect_CoreJstl.jsp

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<html>
<head>
    <title>Import a Page</title>
</head>
<body><frame name="frame1">
        <form method="POST">
            <p>Enter 1 for http://www.roseindia.net<br>
            Enter 2 for http://www.google.com<br>
            Enter 3 for http://www.yahoo.com<br>
            Enter 4 for http://www.msn.com<br>
            <table >
            <tr>
                <td>Enter Your Choice </td>
                <td>
                    <input type="text" name="choice" size="20"/>
                </td>
                <td><input type="submit" value="submit"/></td>
            </tr> 
    </form></frame>
    <c:if test="${pageContext.request.method=='POST'}">
        <c:choose>
            <c:when test="${param.choice=='1'}">
                <c:redirect url="http://www.roseindia.net"/>
            </c:when>
            <c:when test="${param.choice=='2'}">
                <c:redirect url="http://www.google.com"/>
            </c:when>
            <c:when test="${param.choice=='3'}">
                <c:redirect url="http://www.yahoo.com"/>
            </c:when>
            <c:when test="${param.choice=='4'}">
                <c:redirect url="http://www.msn.com"/>
            </c:when>
            <c:otherwise>
                <font color="red"><b>Found wrong choice, try again...</font></b>
            </c:otherwise>
        </c:choose>
    </c:if>
</body>
</html>

Steps to run this example :

1:  Download the zip file of code and unzip this file, you will get a folder named  'redirect_page_jstlCoreTag'.
2:  Paste this folder in 'Apache Tomcat 6.0.16-->webapps' or generally in directory 'C:\apache-tomcat-6.0.16\webapps'.
3:  Start tomcat server by click on startup.bat file in 'C:\apache-tomcat-6.0.16\bin'.
4: Open browser and type url 'http://localhost:8080/redirect_page_jstlCoreTag/redirect_CoreJstl.jsp' or click on this link.

When program will run in browser this will show the following output.....

when user will fill in the text box and click on submit button, next response will be according to the user choice, if user fills choice other than provided in the list, response will be the error message........

Download Source Code

Advertisements

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: August 7, 2008

Ask Questions?    Discuss: Using tag of Core JSTL tags   View All Comments

Post your Comment


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