Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Use of tag of Core JSTL tags 
 

In this example we have used Core JSTL tag that is used to handle exception generated during run time.

 

Use of <c:catch> tag of Core JSTL tags

                         

In this example we have used Core JSTL tag <c:catch> that is used to handle exception generated during run time. Here we will create a simple calculator to divide two numbers, if user enters values instead a digit, it shows a error message as a response. Tag <c:catch> is member of Core tag library of JSTL so before use Core JSTL tags we must include following line of code :-

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

 

 

 



catchException.jsp

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<html>
<head>
<title>Example of tag catch of Core JSTL tags</title>
</head>
<body bgcolor="#A9F5F2">
<form method="POST">
<table>
	<tr>
		<td><input type="text" name="num" size="10" /></td>
		<td>Divide By</td>
		<td><input type="text" name="devider" size="10" /> <input
			type="submit" name="calculate" value="calculate" /></td>
	</tr>
</table>
</form>
<c:if test="${pageContext.request.method=='POST'}">
	<c:catch var="catchException">
		<c:set var="num" value="${param.num}" />
		<c:set var="devider" value="${param.devider}" />
		<b>Response : </b>
		<c:out value="${num/devider}" />
	</c:catch>
	<c:if test="${catchException!=null}">
		<table border="1" width="50%">
		     <tr>
			<td><font color="red" size="4">Found Exception :</font> <c:out
					value=" ${catchException}" /></td>
                     </tr>
		     <tr>
			<td><font color="red" size="4">Exception Message :</font> <c:out
					value="${catchException.message}" /></td>
		     </tr>
		</table>
	</c:if>
</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  'catch_exception_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/catch_exception_jstlCoreTag/catchException.jsp' or click on this link.

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

when user will fill all the fields and click on calculate button, next response will be like as below.......

If user enter values other than digit this will show generated exception as response message. For example user enters a digit in first text box and a string in other text box so the response will be a error message.....

Download Source Code

                         

» View all related tutorials
Related Tags: c xml library file files stl orm ant form io user sed jstl tag parameter transform this js for add

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.