Prints a conversion table of miles per gallon to kilometers per liter : HTML Output « Servlets « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » Servlets » HTML OutputScreenshots 
Prints a conversion table of miles per gallon to kilometers per liter


/**
*  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.
*/
package com.jspcr.servlets;

import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

/**
* Prints a conversion table of miles per gallon
* to kilometers per liter
*/
public class K2MServlet 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
         "<html>"
         "<head>"
         "<title>Fuel Efficiency Conversion Chart</title>"
         "</head>"
         "<body>"
         "<center>"
         "<h1>Fuel Efficiency Conversion Chart</h1>"
         "<table border='1' cellpadding='3' cellspacing='0'>"
         "<tr>"
         "<th>Kilometers per Liter</th>"
         "<th>Miles per Gallon</th>"
         "</tr>"
         );

      // Generate table

      for (double kmpl = 5; kmpl <= 20; kmpl += 1.0) {
         double mpg = kmpl * CONVERSION_FACTOR;
         out.println
            "<tr>"
            "<td align='right'>" + FMT.format(kmpl"</td>"
            "<td align='right'>" + FMT.format(mpg"</td>"
            "</tr>"
            );
      }

      // Generate footer

      out.println
         "</table>"
         "</center>"
         "</body>"
         "</html>"
         );
   }
}

           
       
Prints a-conversion-table-of-miles-per-gallon-Servlet.zip( 92 k)
Related examples in the same category
1. Servlet Output HTML Demo
2. Servlet Display Static HTML
3. Servlet: Print Table
4. Html utilities
5. Html Parse Servlet
w___ww___.__jav___a2s__.co_m_ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.