Books
in black and white
Main menu
Share a book About us Home
Books
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics
Ads

More Java Pitfalls Share Reactor - Daconta M,C.

Daconta M,C. More Java Pitfalls Share Reactor - Wiley publishing, 2003. - 476 p.
ISBN: 0-471-23751-5
Download (direct link): morejavapitfallssharereactor2003.pdf
Previous << 1 .. 90 91 92 93 94 95 < 96 > 97 98 99 100 101 102 .. 166 >> Next

[footer.jsp]" />
14 </jsp:forward>
15 <%
16 }
17 catch (IllegalStateException e) { System.out.println("ERROR: + 2
e.toString()); }
18 }
19 %>
20
Listing 29.2 footer.jsp (continued)
260 Item 29
21 <table width="100%" border="0" cellspacing="0" cellpadding="0">
22 <tr bgcolor="#FFFFFF">
23 <td height="4"></td>
24 </tr>
25 <tr bgcolor="#3399CC">
26 <td height="2"></td>
27 </tr>
28 <tr class="largetext">
29 <td height="19">
30 &nbsp;
31 </td>
32 </tr>
33 <tr bgcolor="#CCCC99">
34 <td height="2"></td>
35 </tr>
36 <tr>
37 <td height="2"> </td>
38 </tr>
39 <tr>
40 <td>
41 <div align="center"><font color="#3399CC">
42 <b><font size="2" face="Arial, Helvetica, sans-serif"><a 2
href="footer.jsp?mode=forward">Help</a></font></b>
43 </div>
44 </td>
45 </tr>
46 </table>
Listing 29.2 (continued)
A finished prototype of your design could look like that shown in Figure 29.2.
When developing JSP Web pages, you need to understand when to use include directives, which are included during the JSP-to-servlet translation phase, and when to use include actions, which are included during request time. In addition, keep in mind that forward operations should always test for IllegalStateException errors. Lastly, it is imperative that you implement the c:import tag to retrieve remote URLs in your JSP Web pages, rather than attempting to use JSP include directives/actions for pages that differ in context from the application being run.
Hopefully, our simple example has shown you proper JSP development strategies that will prevent you from realizing these pitfalls and will allow you to deliver robust JSP applications and dynamic storyboards in a timely manner. It is important to consider that the architecture you have chosen adheres to the Model 1 design, which is considered "page-centric" because application flow is controlled by the JSP page logic. Understand that this could present maintenance problems because of the tight coupling of the flow and the logic, but it seems preferable to those with little experience in Web development, and your tight delivery schedule. A better solution would incorporate a Model 2 architecture that implements a mediating application that decouples hard-coded Web page references.
Form Validation Using Regular Expressions 261
Fruit Stand - Microsoft Internet Explorer provided by \
1 File Edit View Favorites Tools Help
+*Back Search _*jFavoites ^jHirtoiy | [g,-*
Address |?] http7/tocalltf:8080/custornview$/hofne.j$p?rnode=default&top>c=apple ^Go Links
Go glc^j ^Search Web Search Site Page Info - fr~jUp ^HigWgh'.
Fruit Stand
FRUITS INFORMATION
Apple
Banana
Cherrv
Grapes
Orange Apples. Mmm..mmm..good
Pineaople ml
Strawberrv V

Local intranet
Tomcat| 9:15AM
Figure 29.2 Completed prototype.
Item 30: Form Validation Using Regular Expressions
The latest Merlin release (Java SDK 1.4) introduced regular expressions so that developers can manipulate character text in an easier fashion than previously released string handling methods. This enhancement has strengthened the maturing language and facilitated error checking and text manipulation, which is so important to Web application components.
Search and search-and-replace activities are among the more common uses of regular expressions, but they can also be used to perform Boolean tests on text patterns and data streams. Anyone familiar with Unix should recognize regular expressions and their powerful capabilities because of their prevalence in Unix tools and commands. I like to use regular expressions to parse form text and perform validation and replacement activities in my JavaBean components. In Figure 30.1, a Web form demonstrates user validation on input fields and error text that is rendered to the user display when improper data is submitted by the end user. The code that follows will make obvious how important regular expressions can be for Web developers and how the Java language is the "programming language that keeps on giving."
The form above takes user inputs and validates the data prior to passing the application on to the next application in the workflow. The validation bean in Listing 30.1 reads and remembers the user input using the Memento pattern and checks to see if valid entries have been submitted. Improper entries are tagged and sent back to the user display to indicate what the proper input format should be.
262 Item 30
i
Figure 30.1 A Web form.
Telephone numbers are typically character strings separated by delimiters for readability, so our regular expression should capture digits only ranging from 0 to 9 and be linked by dash characters. The telephone number pattern shown on line 36 ensures that a 10-digit value is input by the user and that an optional dash delimiter can be used for input. Several string manipulations would be needed to perform the same operation that is performed in just one line. Note the double backslash notation in the regular expression "\\d", which differs from the single backslash notation used in Perl, because it differentiates escape character values from regular expressions. The brace notation "{}'' indicates the number of decimals values that should be found in the string literal being examined.
Previous << 1 .. 90 91 92 93 94 95 < 96 > 97 98 99 100 101 102 .. 166 >> Next