Java 2EE and XML Development

Скачать в pdf «Java 2EE and XML Development»

Instead, we decided to write four very specific and simple JSPs, one for each permutation of output formats and locales we need to service. See listings 5.4 through 5.7. Each JSP will obtain a handle to the XMLHelper JavaBean that we stored in the request object to render its output.

Listing 5.4 The U.S. English, HTML watch list JSP

Recovers the JavaBean from the request object


Specifies prefix for use as a tag

<jsp:useBean name=»helper» scope=»page»


<%@ taglib uri=»example.tld» prefix=»helperTag» %> <html>

<head><title>Your Watch List</title></head> <body>

<h1>Your Stock Price Watch List</h1>



<jsp:getProperty name=»helper» property=»firstName»/>! </h3>


Here are the latest price quotes for your watch list stocks.

</h3> <p><i>

Price quotes were obtained at

<jsp:getProperty name=»helper» property=»quoteTime»/> on

<jsp:getProperty name=»helper» property=»quoteDate»/>.


<table cellpadding=»5″ cellspacing=»0″ border=»1″>

<helperTag:printData useLinks=»yes» currency=»USD»/>

</table>    Invokes the doStartTag() of

</body>    our XMLHelperBean


О Because we specify useLinks=yes, our custom tag prints an HTML table consisting of four columns with links to buy and sell individual stocks. Setting cur-rency=USD will print all stock prices in U.S. dollars.

The JSP that produces the U.S. English, HTML version of our page is shown in listing 5.4, with its British counterpart given in listing 5.5. Note both the similarities and the differences between the two. The U.S. page uses a bit less formal language and expresses prices in USD. The British version is more formal and shows pricing in British pounds. However, they both use the identical data source and neither has any Java code in it.

Скачать в pdf «Java 2EE and XML Development»