JAVA Q&A
by Paul Tremblett

Listing One
   1| <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
   2| <html>
   3| <head>
   4| <title>JSP Example 1</title>
   5| <meta http-equiv="Content-Type" content="text/html;
   6|   charset=iso-8859-1">
   7| <meta name="Author" content="Paul Tremblett">
   8| <meta name="GENERATOR" content="Mozilla/4.51 [en] (X11; I;
   9|   Linux 2.2.5-15 i586) [Netscape]">
  10| </head>
  11| <body bgcolor="#FFFFFF">
  12| <p>
  13| <font face="Arial, Helvetica, sans-serif"><b><font size="+2">
  14| JSP Example 1
  15| </font></b></font>
  16| <br>
  17| <br>
  18| <font face = "Arial, Helvetica"><font size="+1">
  19| It is now
  20| <%=
  21| new java.util.GregorianCalendar(new java.util.SimpleTimeZone
  22|    (-5*60*60*1000,"EDT")).getTime()
  23| %>
  24| </font>
  25| </body>
  26| </html>

Listing Two
   1| <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
   2| <html>
   3| <head>
   4| <title>JSP Example 2</title>
   5| <meta http-equiv="Content-Type" content="text/html;
   6|   charset=iso-8859-1">
   7| <meta name="Author" content="Paul Tremblett">
   8| <meta name="GENERATOR" content="Mozilla/4.51 [en] (X11; I;
   9|   Linux 2.2.5-15 i586) [Netscape]">
  10| </head>
  11| <body bgcolor="#FFFFFF">
  12| <p>
  13| <font face="Arial, Helvetica"><b><font size="+2">
  14| <center>
  15| JSP Example 2
  16| </font></b></font><br>
  17| <br>
  18| <font face = "Arial, Helvetica, sans-serif"><font size="+1">
  19| <b><u>Some Info About Your Request:</u></b>
  20| </center>
  21| <br>
  22| Protocol:
  23| <%= request.getProtocol() %>
  24| <br>
  25| Remote Addr:
  26| <%= request.getRemoteAddr() %>
  27| <br>
  28| Remote Host:
  29| <%= request.getRemoteHost() %>
  30| <br>
  31| URL Scheme:
  32| <%= request.getScheme() %>
  33| <br>
  34| Server Name:
  35| <%= request.getServerName() %>
  36| <br>
  37| Server Port:
  38| <%= request.getServerPort() %>
  39| </font>
  40| </body>
  41| </html>

Listings Three
   1| <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
   2| <html>
   3| <head>
   4| <title>DDJ Article Lister</title>
   5| <meta http-equiv="Content-Type" content="text/html;
   6|   charset=iso-8859-1">
   7| <meta name="Author" content="Paul Tremblett">
   8| <meta name="GENERATOR" content="Mozilla/4.51 [en] (X11; I;
   9|   Linux 2.2.5-15 i586) [Netscape]">
  10| </head>
  11| <body bgcolor="#FFFFFF">
  12| <%@ page language="java" import="ddj.*" %>
  13| <%@ page info="DDJ Article Lister V1.0" %>
  14| <%@ page errorPage="errorpage.jsp" %>
  15| <jsp:useBean id="articles" scope="request"
  16|   class="ddj.Articles" />
  17| <%
  18|   articles.processRequest(request);
  19|   String month = articles.getMonth();
  20|   String[][] articleList = articles.getArticles(month);
  21|   if (articleList.length == 0) {
  22| %>
  23| <%@ include file = "NoData.jsp" %>
  24| <%
  25|   }
  26|   else {
  27| %>
  28| <center>
  29| <table cellspacing=0 cols=2 width="80%">
  30| <caption><b><font face="Arial, Helvetica"><font size=+1>
  31| Dr. Dobb's Articles For The Month Of
  32| <%= month %>
  33| 1999
  34| </font></font></b>
  35| </caption>
  36| <%! String[] alternatingColors = {"#ffff99", "#ffcc99"}; %>
  37| <%
  38|     for (int i = 0; i < articleList.length; ++i) {
  39| %>
  40| <tr bgcolor=
  41| <%=alternatingColors[i % 2] %>
  42| >
  43| <td>
  44| <b>
  45| <%= articleList[i][0] %>
  46| </b>
  47| </td>
  48| <td>
  49| <b>
  50| <%= articleList[i][1] %>
  51| </b>
  52| </td>
  53| </tr>
  54| <%
  55|     }
  56| %>
  57| </table>
  58| <form method=get action="ArticleLister.html">
  59| <input type=submit name="submit" value="BACK">
  60| </form>
  61| </center>
  62| <%
  63|   }
  64| %>
  65| </body>
  66| </html>

Listing Four
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title>DDJ Article Lister</title>
<meta http-equiv="Content-Type" content="text/html;
  charset=iso-8859-1">
<meta name="Author" content="Paul Tremblett">
<meta name="GENERATOR" content="Mozilla/4.51 [en] (X11;
  I; Linux 2.2.5-15 i586) [Netscape]">
</head>
<body bgcolor="#FFFFFF">
<p>
<font face="Arial, Helvetica, sans-serif"><b><font size="+2">
<center>
DDJ Article Lister
</font></b></font><br>
<br>
<font face = "Arial, Helvetica, sans-serif"><font size="+1">
Select a month from the list below:
<form method="post" action="ArticleLister.jsp">
<select name="month" size=4>
<option value="January">January
<option value="February">February
<option value="March">March
<option value="April">April
<option value="May">May
<option value="June">June
<option value="July">July
<option value="August">August
<option value="September">September
<option value="October">October
<option value="November">November
<option value="December">December
</select>
<br>
<br>
<br>

<input type="submit" name="submit" value="GET ARTICLES">
</form>
</center>
</body>
</html>


Listing Five
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title>DDJ Article Lister</title>
<meta http-equiv="Content-Type" content="text/html;
  charset=iso-8859-1">
<meta name="Author" content="Paul Tremblett">
<meta name="GENERATOR" content="Mozilla/4.51 [en] (X11; I;
  Linux 2.2.5-15 i586) [Netscape]">
</head>
<body bgcolor="#ff0000">
<%@ page isErrorPage="true" %>
<center>
<br>
<br>
<h1> Error:
<%= exception.getMessage() %>
</h1>
<form action="ArticleLister.html">
<input type="submit" value="Try Again">
</form>
</CENTER>
</body>
</html>





