/**
* Copyright (c) 2002 by Phil Hanna
* All rights reserved.
*
* You may study, use, modify, and distribute this
* software for any purpose provided that this
* copyright notice appears in all copies.
*
* This software is provided without warranty
* either expressed or implied.
*/
import java.text.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class MyServlet extends HttpServlet {
/**
* Numeric format used to display temperatures
*/
private static final DecimalFormat FMT
= new DecimalFormat("#0.00");
/**
* Factor to convert from km/l to mi/gal
*/
private static final double CONVERSION_FACTOR = 2.352145;
/**
* Handles a GET request
*/
public void doGet(
HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
// Set up for creating HTML output
response.setContentType("text/html");
PrintWriter out = response.getWriter();
// Generate heading
out.println
( ""
+ ""
+ "Fuel Efficiency Conversion Chart "
+ ""
+ ""
+ ""
+ "Fuel Efficiency Conversion Chart
"
+ ""
+ ""
+ "Kilometers per Liter "
+ "Miles per Gallon "
+ " "
);
// Generate table
for (double kmpl = 5; kmpl <= 20; kmpl += 1.0) {
double mpg = kmpl * CONVERSION_FACTOR;
out.println
( ""
+ "" + FMT.format(kmpl) + " "
+ "" + FMT.format(mpg) + " "
+ " "
);
}
// Generate footer
out.println
( "
"
+ " "
+ ""
+ ""
);
}
}
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
name
John
password
password
MyServletName
MyServlet
MyServletName
/index.html