Java
  Home arrow Java arrow Page 5 - The JSP Files (part 7): Bugs, Beans An...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

The JSP Files (part 7): Bugs, Beans And Banks
By: Vikram Vaswani and Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 2
    2001-04-18

    Table of Contents:
  • The JSP Files (part 7): Bugs, Beans And Banks
  • Bugathon
  • Exceptionally Clever
  • Bad News
  • You Throw(), I'll Catch
  • Bean Bag
  • Turning Up The Heat

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    The JSP Files (part 7): Bugs, Beans And Banks - You Throw(), I'll Catch


    (Page 5 of 7 )

    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 Articles
    More By Vikram Vaswani and Harish Kamath, (c) Melonfire


     

       

    JAVA ARTICLES

    - New Object Initialization in Java
    - Adding Images With iTextSharp
    - Adding Columns With iTextSharp
    - Creating Simple PDF Files With iTextSharp
    - The Spring Framework: Understanding IoC
    - Introducing the Spring Framework
    - Java Classes
    - Completing the Syntactic Comparison of Java ...
    - Syntactic Comparison of Java and C/C++
    - Java Statements
    - Conditionals, Expressions and Other Java Ope...
    - Java Operators
    - Primitive Data Types and Basic Language Rule...
    - Java and Object-Oriented Programming
    - Java Beginning Programming





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway