Java/JSP/HTML Output — различия между версиями

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

Текущая версия на 07:10, 1 июня 2010

Celsius Fahrenheit Table Jsp

<%--
  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" %>
<table border="0" align="center" width="50%">
<tr>
   <th align="right">Celsius</th>
   <th align="right">Fahrenheit</th>
</tr>
<%
   for (int c = 0; c <= 100; c += 10) {
      int f = 32 + 9*c/5;
      out.print("<tr>");
      out.print("<td align=\"right\">" + c + "</td>");
      out.print("<td align=\"right\">" + f + "</td>");
      out.print("</tr>");
   }
%>
</table>





JSP HTML Table

Output HTML

<%--
  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("<code>out</code> is an <i>");
   out.println(out.getClass().getName());
   out.println("</i> object.");
%>





Output Simple HTML Tag Jsp

Print ASCII Table Jsp

<%--
  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>
<center>
<h1>ASCII Table</h1>
<table border="0" cellpadding="0" cellspacing="0">
<%
   StringBuffer sb = new StringBuffer();
   sb.append("<tr>");
   sb.append("<th width=\"40\">&nbsp;</th>");
   for (int col = 0; col < 16; col++) {
      sb.append("<th>");
      sb.append(Integer.toHexString(col));
      sb.append("</th>");
   }
   sb.append("</tr>");
   for (int row = 0; row < 16; row++) {
      sb.append("<tr>");
      sb.append("<th>");
      sb.append(Integer.toHexString(row));
      sb.append("</th>");
      for (int col = 0; col < 16; col++) {
         char c = (char)(row * 16 + col);
         sb.append("<td width=\"32\" align=\"center\">");
         sb.append(c);
         sb.append("</td>");
      }
      sb.append("</tr>");
   }
   out.println(sb);
%>
</table>
</center>
</body>
</html>





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.
--%>
<%@ 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>
<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>
<%
   for (double kmpl = 5; kmpl <= 20; kmpl += 1.0) {
      double mpg = kmpl * CONVERSION_FACTOR;
%>
   <tr>
      <td align="right"><%= FMT.format(kmpl) %></td>
      <td align="right"><%= FMT.format(mpg) %></td>
   </tr>
<% } %>
</table>
</center>
</body>
</html>