Java Reference
In-Depth Information
currency + "</option>");
}
%>
</select><br>
Ending currency:
<select name="endingCurrency">
<%
Iterator endIter = Currency.getCurrencies();
while (endIter.hasNext()) {
String currency = (String) endIter.next();
out.println("<option value=\"" + currency + "\">" +
currency + "</option>");
}
%>
</select><br>
Amount: <input type="text" name="amount" size="6" value="10"><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
Because this web application is extremely simple and informal, let's break a tenet
of web application design and embed the business logic of the conversion into a
JSP (see listing 11.4). Typically, this is a bad idea: For enterprise applications,
business logic should exist in its own layer where it can be centrally managed and
be presented through multiple channels without having any sort of tight coupling
to the presentation layer that controls what a client sees and how they see it. But
because you're looking specifically at exercising IDEA 's web application and JSP
features, we don't think anyone will object.
The resulting JSP , therefore, is responsible for two things: accepting the
incoming parameters and performing the business logic of a currency exchange
on them, and presenting the results to the client. You can implement the former
by putting a scriptlet at the top of the page that reads the incoming parameters,
parses them, and uses them as input to the exchange process. The latter can use a
combination of static HTML and JSP expressions to show those results.
Don't forget to use some of IDEA 's efficiency features (such as refactoring, code
generation, live templates, and so on) as you implement this page.
Listing 11.4
The resulting JSP that does the calculation and shows the result to
the client
<%@ page
import="com.acme.conversion.currency.service.CurrencyExchangeService,
com.acme.conversion.currency.service.CurrencyExchangeServiceFactory,
 
 
Search WWH ::




Custom Search