Exception Handling using JSTL tag….

Here in this post we will learn how to handle Exception in jsp page using JSTL tags

Here is the sample code for this app…


<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<strong>Exception Handling Example</strong><br>
<a href="<c:url value='Check.jsp' />" >Go to Exception Page</a><br>
<%-- The above line is similar to response.encodeURL("url") method of servlet --%>

when we click on Go to Exception Page it will send u too Check.jsp page contain the following code:

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

<strong>Exception Handling Example</strong>
<c:catch var=”myexception” ><%—This is similar to try { }catch{} of normal exception handling –-%>
<strong>Inside the Catch Block : >></strong>
<% int x = 10/0; %>
<%– the <c:chosoe> , c:when and c:otherwise is equivalant to if {}else {} statement !! thanx –%>

<c:when test=”${myexception != null}” >
There was an Exception : ${myexception.message}<br><br>
<c:otherwise >
No Problem thanks!!
</c:otherwise >

at int x=10/0; there is devide by zero exception which is catch by the above given block

the running example can be found here

Handling 404 with exception handling in JSP

Here we are going to discuss simple way to handling 404 page Not found error and exception handling in jsp :

here is the directory structure of this simple app :


just download this app from here and call some page like xyz.jsp the it will show u the output like this :


what happening inside the app is all about this code :





when we request for some page which is not inside the web app then the container automatically detects that by reading the above web.xml code and redirect request to the given page which is notFound.jsp as given above. so u can create your own custom not found page and use it in your web applicatin!!.

the second part of this app is to handle some exception in jsp. here in the above given dierctory struc. error.jsp page has some exception :


<%@ page errorPage=”errorhandler.jsp” %><%– errorhandler.jsp  page will Handle the Error found in this page –%>
<strong>Welcome to web App Test</strong>
<% int x = 10/0; %><%– here is the exp. –%>


this could also done by configuring in web.xml for example if a page has java.lang.ArithmeticException then it could be handled by adding this code in web.xml:

<location>/notFound1.jsp</location><!– this page will be handle the the exception –>


use it in your application and enjoy @@. feel free to ask if you get any problem….

J2EE Application Into The Cloud . . .

Hi Friends,

Here we quickly find out how to deploy our j2ee application into the cloud by just following some steps:

Step 1: First You will need to select your cloud service Provider and create an account.

There are several Cloud Providers who provide a limited capable account for free

and those are :
Open Shift (from Red Hat Inc.)

CloudFoundry (from Vmware Inc. )



Step 2. Create your web app using the technologies provide/supported by the cloud provider.

Here we are using OpenShift for J2EE apps. When using eclipse IDE  then cont.


Sorry @@ this topic will be continue later due to some other project work i am busy there @@