img
e = -(payPerYear * numYears);
b = (intRate / payPerYear) + 1.0;
denom = 1.0 - Math.pow(b, e);
return numer / denom;
}
}
The first thing to notice about RegPayS is that it has only two methods: doGet( ) and
compute( ). The compute( ) method is the same as that used by the applet. The doGet( )
method is defined by the HttpServlet class, which RegPayS extends. This method is called by
the server when the servlet must respond to a GET request. Notice that it is passed a reference
to the HttpServletRequest and HttpServletResponse objects associated with the request.
From the request parameter, the servlet obtains the arguments associated with the
request. It does this by calling getParameter( ). The parameter is returned in its string form.
Thus, a numeric value must be manually converted into its binary format. If no parameter
is available, a null is returned.
From the response object, the servlet obtains a stream to which response information
can be written. The response is then returned to the browser by outputting to that stream.
Prior to obtaining a PrintWriter to the response stream, the output type should be set to
text/html by calling setContentType( ).
RegPayS can be called with or without parameters. If called without parameters, the
servlet responds with the necessary HTML to display an empty loan calculator form.
Otherwise, if called with all needed parameters, RegPayS calculates the loan payment and
redisplays the form, with the payment field filled in. Figure 32-7 shows the RegPayS servlet
in action.
FIGURE 32-7
The RegPayS
ser vlet in action
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks
Home