Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
262
Chapter 11 The JSP page Directive: Structuring Generated Servlets
Listing 11.5 ComputeSpeed.jsp (continued)
<%!
// Note lack of try/catch for NumberFormatException if
// value is null or malformed.
private double toDouble(String value) {
return(Double.valueOf(value).doubleValue());
}
%>
<%
double furlongs = toDouble(request.getParameter("furlongs"));
double fortnights = toDouble(request.getParameter("fortnights"));
double speed = furlongs/fortnights;
%>
Distance: <%= furlongs %> furlongs.
Time: <%= fortnights %> fortnights.
Speed: <%= speed %> furlongs per fortnight.