Home arrow Java & J2EE arrow Page 5 - The JSP Files (part 7): Bugs, Beans And Banks

You Throw(), I'll Catch - Java

In this week's episode, find out how the JSP Exception objectprovides developers with a graceful way to recover from script errors. Andthen take a quick tour of the JSP directives you need to know in order tointegrate standalone JavaBeans into your JSP scripts.

  1. The JSP Files (part 7): Bugs, Beans And Banks
  2. Bugathon
  3. Exceptionally Clever
  4. Bad News
  5. You Throw(), I'll Catch
  6. Bean Bag
  7. Turning Up The Heat
By: Vikram Vaswani and Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 2
April 18, 2001

print this article


It's also possible to use the Java "throw" construct to artificially induce an exception in your JSP script. This comes in handy, for example, when validating form field data - if the values entered are not in the expected format, you can throw an exception (with an informative error message) and re-direct the user to an error page.

Here's an example of how this can be used. This is a simple form which asks you to enter a number

<html> <head> <basefont face="Arial"> </head> <body> <form action="number.jsp"> Enter a number between 1 and 3 <input type=text name=number size=1> </form> </body> </html>

and this is the server-side JSP script which checks it for errors, and throws an exception if certain conditions are not met.

<html> <head> <basefont face="Arial"> </head> <body> <%@ page errorPage="error.jsp" %> <% String temp = request.getParameter("number"); int number = Integer.parseInt(temp); if (number != 2) { throw new Exception ("How dumb can you get?!") ; } else { out.println("Hmmm...maybe you're not as dumb as you look!"); } %> </body> </html>

Next up, a brief look at JavaBeans and how they integrate with the JSP environment.

>>> More Java & J2EE Articles          >>> More By Vikram Vaswani and Harish Kamath, (c) Melonfire

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- More Java Bugs Lead to More Attacks
- Oracle's Java One Brings News, Surprises
- Oracle Patches Java Runtime Environment
- Apple Syncs Java Update with Oracle
- Spring 3.1 Java Development Framework Compat...
- Jelastic Java PaaS Availability and Pricing ...
- NetBeans 7.1 Released, Supports JavaFX 2
- SolarWinds Releases Newest Version of Java M...
- Free Monitoring Tool for Java Apps on Heroku
- Heroku Adds JCloud Platform Support, Java 7 ...
- Java SE 8 Speculation in Full Swing
- Java SE 7 Now Available
- New JVM Language and Java Reporting Tool
- Java 7 Release Update and New Eclipse Toolkit
- The Best Java Netbeans IDE Plugins

Developer Shed Affiliates


Dev Shed Tutorial Topics: