JavaServer Page

January 30, 2007

Adding assertions and input validation B Gets a

Filed under: JSP Tag Libraries — webmaster @ 4:35 pm

CHAPTER 7 Building a tag library for sending email exists false false oneof false false Listing 7.20 shows how all the attributes in AssertTag are constant strings. Why did we exclude runtime expressions for this tag? Because translation time validation of runtime attributes is impossible, and incorrectly configured assertions may cause problems ranging from plain embarrassment (this site is throwing exceptions instead of showing a reasonable error page) to profit loss (if the assertion needs to rule out stolen credit card numbers). By preventing assertions from being runtime expressions, we discover any syntax problems in our attributes before the page is requested by a user (at translation time), and well before any damage can occur. It is preferable to be safe than sorry, so we ve decided that the assertion tag is one such case. Using assertion mail tags in the registration JSP file Having developed the assertions, let s use them in our registration page (listing 7.21). In its current sample state, the registration page accepts three parameters: The user s email Validate with an existence and type (email) assertions. The user s name Validate with an existence and type (alpha) assertions. The user s family name Validate with an existence and type (alpha) assertions. An error in any one of the three parameters ought to trigger an internal redirection to an error handler that will present the offending parameter. Listing 7.21 A JSP file employing the assertion email tags < %@ taglib uri="http://www.manning.com/jsptagsbook/email-taglib" prefix="mail" %> < %@ taglib uri="http://www.manning.com/jsptagsbook/assert-taglib" prefix="assert" %>

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost JSP Web Hosting services

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URI

Sorry, the comment form is closed at this time.

Powered by Java Web Hosting