Catch Error : Exception « JSTL « Java Tutorial

Home
Java Tutorial
1.Language
2.Data Type
3.Operators
4.Statement Control
5.Class Definition
6.Development
7.Reflection
8.Regular Expressions
9.Collections
10.Thread
11.File
12.Generics
13.I18N
14.Swing
15.Swing Event
16.2D Graphics
17.SWT
18.SWT 2D Graphics
19.Network
20.Database
21.Hibernate
22.JPA
23.JSP
24.JSTL
25.Servlet
26.Web Services SOA
27.EJB3
28.Spring
29.PDF
30.Email
31.J2ME
32.J2EE Application
33.XML
34.Design Pattern
35.Log
36.Security
37.Apache Common
38.Ant
39.JUnit
Java Tutorial » JSTL » Exception 
24.13.5.Catch Error

index.jsp

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

<h1>Peter's Junk-Mail Service</h1>

<c:if test="${param.submitted}">
  <c:if test="${empty param.name}" var="noName" />
  <c:if test="${empty param.email}" var="noEmail" />
  <c:if test="${empty param.age}" var="noAge" />

  <c:catch var="ageError">
    <fmt:parseNumber var="parsedAge" value="${param.age}" />
    <c:if test="${parsedAge < 13}" var="youngAge" />
  </c:catch>
  <c:if test="${not empty ageError}" var="badAge" />

  <c:if
   test="${not (noName or noEmail or noAge or badAge or youngAge)}">
    <c:set value="${param.name}" var="name" scope="request"/>
    <c:set value="${param.email}" var="email" scope="request"/>
    <c:set value="${param.age}" var="age" scope="request"/>
    <jsp:forward page="spamFormHandler.jsp" />
  </c:if>
</c:if>

<form method="post">
  <P>
  Thanks for signing up for our junk-mail service.
  Once you submit your information on the form below,
  you'll begin to receive all the "spam" you ever wanted.
  </p>

  <input type="hidden" name="submitted" value="true" />

  <P>
  Enter your name:
  <input type="text" name="name"
    value="<c:out value="${param.name}"/>" />
  <br />
  <c:if test="${noName}">
   <small><font color="red">
     Note: you must enter a name
   </font></small>
  </c:if>
  </p>

  <P>
  Enter your email address:
  <input type="text" name="email"
    value="<c:out value="${param.email}"/>" />
  <br />
  <c:if test="${noEmail}">
   <small><font color="red">
     Note: you must enter an email address
   </font></small>
  </c:if>
  </p>

  <P>
  Enter your age:
  <input type="text" name="age" size="3"
    value="<c:out value="${param.age}"/>" />
  <br />
  <c:choose>
    <c:when test="${noAge}">
     <small><font color="red">
       Note: you must enter your age
     </font></small>
    </c:when>
    <c:when test="${badAge}">
     <small><font color="red">
       Note: I couldn't decipher the age you typed in
     </font></small>
    </c:when>
    <c:when test="${youngAge}">
     <small><font color="red">
       Note: You're too young to receive pornographic
       junk mail.  Please grow older and try again.
     </font></small>
    </c:when>
  </c:choose>
  </p>

  <input type="submit" value="Sign up" />

</form>

spamFormHandler.jsp

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

<h4>
 <font face="arial">
  Excellent!  The information is now correct.  (We could save it in a
  database or process it further.)
 </font>
</h4>
  Download:  JSTLCatchError.zip( 939 k)
24.13.Exception
24.13.1.Generate Exception in c:out
24.13.2.C:Catch Exception
24.13.3.Catch Exception and Print Out Exception Message
24.13.4.Catch Exception
24.13.5.Catch Error
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.