Java/JSP/HTML Output

Материал из Java эксперт
Перейти к: навигация, поиск

Celsius Fahrenheit Table Jsp

   <source lang="java">

<%--

 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.

--%> <%@ page session="false" %>

<% for (int c = 0; c <= 100; c += 10) { int f = 32 + 9*c/5; out.print(""); out.print(""); out.print(""); out.print(""); } %>
Celsius Fahrenheit
" + c + "" + f + "


      </source>
   
  
 
  



JSP HTML Table

Output HTML

   <source lang="java">

<%--

 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.

--%> <%@ page session="false" %> <%

  out.println("out is an ");
  out.println(out.getClass().getName());
  out.println(" object.");

%>


      </source>
   
  
 
  



Output Simple HTML Tag Jsp

Print ASCII Table Jsp

   <source lang="java">

<%--

 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.

--%> <%@ page session="false" %> <html> <body>

ASCII Table

<% StringBuffer sb = new StringBuffer(); sb.append(""); sb.append("");
  for (int col = 0; col < 16; col++) {
sb.append(""); } sb.append(""); for (int row = 0; row < 16; row++) { sb.append(""); sb.append(""); for (int col = 0; col < 16; col++) { char c = (char)(row * 16 + col); sb.append(""); } sb.append(""); } out.println(sb); %>
 ");
     sb.append(Integer.toHexString(col));
sb.append("
");
     sb.append(Integer.toHexString(row));
sb.append("
");
        sb.append(c);
sb.append("

</body> </html>


      </source>
   
  
 
  



Prints a conversion table of miles per gallon to kilometers per liter

   <source lang="java">

<%--

 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.

--%> <%@ page session="false" %> <%@ page import="java.io.*" %> <%@ page import="java.text.*" %> <%@ page import="java.util.*" %> <%-- Prints a conversion table of miles per gallon

     to kilometers per liter --%>

<%!

  private static final DecimalFormat FMT
     = new DecimalFormat("#0.00");
  private static final double CONVERSION_FACTOR = 2.352145;

%> <html> <head> <title>Fuel Efficiency Conversion Chart</title> </head> <body>

Fuel Efficiency Conversion Chart

<% for (double kmpl = 5; kmpl <= 20; kmpl += 1.0) { double mpg = kmpl * CONVERSION_FACTOR; %> <% } %>
Kilometers per Liter Miles per Gallon
<%= FMT.format(kmpl) %> <%= FMT.format(mpg) %>

</body> </html>


      </source>