站内搜索: 请输入搜索关键词
当前页面: 图书首页 > JavaServer Pages, Second Edition

JavaServer Pages, Second Edition

[ directory ] Previous Section Next Section

Chapter 3. Using Beans

The examples in Chapter 2 were quite simple, although they did illustrate a few important points. Notably, these examples demonstrated how a JSP file is converted into a little program and how this program can then perform certain actions when it is run. What is needed now is a mechanism for pages to react to user input and other data.

A page may need to react to such information in any of several ways. For example, a page that displays a stock portfolio typically uses green text to show the stocks that have increased in value and uses red to show those that have decreased in value. Here the page needs to display a value and also change an aspect of its appearance, based on the value.

A page might also want to use a value in a complex calculation or process. In the online portfolio, once a "buy" order is placed, the current status of the user's account must be checked to ensure that it contains sufficient funds to cover the purchase and any transaction fees. If this condition is met, the order must be handled, which entails a number of processes behind the scenes. In either case, the result of the request must then be reported back to the user.

The first kind of reaction, in which the presentation of the page is altered, can be handled either by putting Java code within the page itself or by using special JSP tags. But before diving into the second type of reaction, it is worth discussing the more general problem of software engineering.

    [ directory ] Previous Section Next Section