import java.io.*; import javax.servlet.*; import javax.servlet.http.*; //extends HttpServlet always included in Servlet public class ExampServlet extends HttpServlet { //doPost method processes request and response public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //response will be in text/html response.setContentType("text/html"); //set up a print writer for the response PrintWriter out = response.getWriter(); //write the html to the print writer out.println("Example" + ""); out.println("

Your Mortgage Calculation

"); //get String Parameters from the form String DATA = request.getParameter("DATA"); //Note: all strings must be converted to numeric if //needed for calculations. //process the form parameters, additional business objects //can be added here //add code here to check for numeric and display message //if input error double amount = Double.parseDouble(request.getParameter("amount")); double rate = Double.parseDouble(request.getParameter("rate")); int years = Integer.parseInt(request.getParameter("years")); double monthlyInterest = rate/12/100; int months = years * 12; //Use FinancialCalculations methods double payment = FinancialCalculations.calculateMonthlyPayment( amount, months, monthlyInterest); String Payment = String.valueOf(payment); double futureValue = FinancialCalculations.calculateFutureValue (payment, months, monthlyInterest); String fv = String.valueOf(futureValue); //Add code here to convert to currency //** if(Payment != null){ out.println("Payment: "+ Payment); out.println("Future Value: "+ fv); } else { out.println("Nothing entered."); } //http address point to page to return to out.println("

To visit a web CourseClick Here
"); out.println("Or use your browsers back button to return to form

"); out.close(); } }