Java The Complete Reference, Seventh Edition

(Greg DeLong) #1
The simplest way to invokeRegPaySis to link to its URL without passing any parameters.
For example, assuming that you are using Tomcat, you can use this line to execute it:

<A HREF = "http://localhost:8080/servlets-examples/servlet/RegPayS">
Loan Calculator</A>

This displays a link called Loan Calculator that links to theRegPaySservlet in the Tomcat
example servlets directory. Notice that no parameters are passed. This causesRegPaySto
return the complete HTML that displays an empty loan calculator page.
You can also invokeRegPaySby first displaying an empty form manually, if you like.
This approach is shown here, again using Tomcat’s example servlets directory:

<html>
<body>
<form name="Form1"
action="http://localhost:8080/servlets-examples/servlet/RegPayS">
<B>Enter amount to finance:</B>
<input type=textbox name="amount" size=12 value="">
<BR>
<B>Enter term in years:</B>
<input type=textbox name="period" size=12 value="">
<BR>
<B>Enter interest rate:</B>
<input type=textbox name="rate" size=12 value="">
<BR>
<B>Monthly Payment:</B>
<input READONLY type=textbox name="payment"
size=12 value="">
<BR><P>
<input type=submit value="Submit">
</form>
</body>
</html>

Some Things to Try


The first thing you might want to try is converting the other financial applets into servlets.
Because all the financial applets are built on the same skeleton, simply follow the same
approach as used byRegPayS. There are many other financial calculations that you might
find useful to implement as applets or servlets, such as the rate of return of an investment
or the amount of a regular deposit needed over time to reach a future value. You could also
print a loan amortization chart. You might want to try creating a larger application that
offers all the calculations presented in this chapter, allowing the user to select the desired
calculation from a menu.

Chapter 32: Financial Applets and Servlets 963

Free download pdf