You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ho...@locus.apache.org on 2000/08/17 02:58:21 UTC
cvs commit: jakarta-tomcat-4.0/webapps/examples/servlets cookies.html helloworld.html index.html reqheaders.html reqinfo.html reqparams.html sessions.html
horwat 00/08/16 17:58:20
Added: webapps/examples/WEB-INF web.xml
webapps/examples/WEB-INF/classes CookieExample.java
HelloWorldExample.java LocalStrings.properties
LocalStrings_en.properties
LocalStrings_es.properties
RequestHeaderExample.java RequestInfoExample.java
RequestParamExample.java SessionExample.java
SnoopServlet.java servletToJsp.java
webapps/examples/WEB-INF/classes/cal Entries.java Entry.java
JspCalendar.java TableBean.java
webapps/examples/WEB-INF/classes/checkbox CheckTest.java
webapps/examples/WEB-INF/classes/colors ColorGameBean.java
webapps/examples/WEB-INF/classes/dates JspCalendar.java
webapps/examples/WEB-INF/classes/error Smart.java
webapps/examples/WEB-INF/classes/examples
ExampleTagBase.java FooTag.java
FooTagExtraInfo.java LogTag.java ShowSource.java
webapps/examples/WEB-INF/classes/num NumberGuessBean.java
webapps/examples/WEB-INF/classes/sessions DummyCart.java
webapps/examples/WEB-INF/jsp example-taglib.tld
webapps/examples/WEB-INF/jsp/applet Clock2.java
webapps/examples/images code.gif execute.gif return.gif
webapps/examples/jsp index.html source.jsp
webapps/examples/jsp/cal Entries.txt Entry.txt
JspCalendar.txt TableBean.txt cal1.jsp cal1.txt
cal2.jsp cal2.txt calendar.html login.html
webapps/examples/jsp/checkbox CheckTest.html check.html
checkresult.jsp checkresult.txt cresult.html
webapps/examples/jsp/colors ColorGameBean.html clr.html
colors.html colors.txt colrs.jsp
webapps/examples/jsp/dates date.html date.jsp date.txt
webapps/examples/jsp/error er.html err.jsp err.txt
error.html errorpge.jsp
webapps/examples/jsp/forward er.html err.jsp err.txt
error.html errorpge.jsp
webapps/examples/jsp/include foo.html foo.jsp inc.html
include.jsp include.txt
webapps/examples/jsp/jsptoserv hello.jsp jsptoservlet.jsp
jts.html jts.txt stj.txt
webapps/examples/jsp/num numguess.html numguess.jsp
numguess.txt
webapps/examples/jsp/plugin plugin.html plugin.jsp
plugin.txt
webapps/examples/jsp/plugin/applet Clock2.java
webapps/examples/jsp/security/login error.jsp login.jsp
webapps/examples/jsp/security/protected index.jsp
webapps/examples/jsp/sessions DummyCart.html carts.html
carts.jsp carts.txt crt.html
webapps/examples/jsp/simpletag foo.html foo.jsp foo.txt
webapps/examples/jsp/snp snoop.html snoop.jsp snoop.txt
webapps/examples/servlets cookies.html helloworld.html
index.html reqheaders.html reqinfo.html
reqparams.html sessions.html
Log:
webapps examples files
Revision Changes Path
1.1 jakarta-tomcat-4.0/webapps/examples/WEB-INF/web.xml
Index: web.xml
===================================================================
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
<servlet>
<servlet-name>
snoop
</servlet-name>
<servlet-class>
SnoopServlet
</servlet-class>
<!--
<init-param>
<param-name>foo</param-name>
<param-value>bar</param-value>
</init-param>
-->
</servlet>
<servlet>
<servlet-name>
servletToJsp
</servlet-name>
<servlet-class>
servletToJsp
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>
snoop
</servlet-name>
<url-pattern>
/snoop
</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>
snoop
</servlet-name>
<url-pattern>
*.snp
</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>
servletToJsp
</servlet-name>
<url-pattern>
/servletToJsp
</url-pattern>
</servlet-mapping>
<taglib>
<taglib-uri>
http://java.apache.org/tomcat/examples-taglib
</taglib-uri>
<taglib-location>
/WEB-INF/jsp/example-taglib.tld
</taglib-location>
</taglib>
<security-constraint>
<web-resource-collection>
<web-resource-name>Protected Area</web-resource-name>
<!-- Define the context-relative URL(s) to be protected -->
<url-pattern>/jsp/security/protected/*</url-pattern>
<!-- If you list http methods, only those methods are protected -->
<http-method>DELETE</http-method>
<http-method>GET</http-method>
<http-method>POST</http-method>
<http-method>PUT</http-method>
</web-resource-collection>
<auth-constraint>
<!-- Anyone with one of the listed roles may access this area -->
<role-name>tomcat</role-name>
<role-name>role1</role-name>
</auth-constraint>
</security-constraint>
<!-- Default login configuration uses BASIC authentication -->
<!--
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>Example Basic Authentication Area</realm-name>
</login-config>
-->
<!-- If you want to experiment with form-based logins, comment
out the <login-config> element above and replace it with
this one. Note that we are currently using a nonstandard
authentication method, because the code to support form
based login is incomplete and only lightly tested. -->
<login-config>
<auth-method>FORM</auth-method>
<realm-name>Example Form-Based Authentication Area</realm-name>
<form-login-config>
<form-login-page>/jsp/security/login/login.jsp</form-login-page>
<form-error-page>/jsp/security/login/error.jsp</form-error-page>
</form-login-config>
</login-config>
</web-app>
1.1 jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/CookieExample.java
Index: CookieExample.java
===================================================================
/* $Id: CookieExample.java,v 1.1 2000/08/17 00:57:52 horwat Exp $
*
*/
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* Example servlet showing request headers
*
* @author James Duncan Davidson <du...@eng.sun.com>
*/
public class CookieExample extends HttpServlet {
ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<body bgcolor=\"white\">");
out.println("<head>");
String title = rb.getString("cookies.title");
out.println("<title>" + title + "</title>");
out.println("</head>");
out.println("<body>");
// relative links
// XXX
// making these absolute till we work out the
// addition of a PathInfo issue
out.println("<a href=\"/examples/servlets/cookies.html\">");
out.println("<img src=\"/examples/images/code.gif\" height=24 " +
"width=24 align=right border=0 alt=\"view code\"></a>");
out.println("<a href=\"/examples/servlets/index.html\">");
out.println("<img src=\"/examples/images/return.gif\" height=24 " +
"width=24 align=right border=0 alt=\"return\"></a>");
out.println("<h3>" + title + "</h3>");
Cookie[] cookies = request.getCookies();
if (cookies.length > 0) {
out.println(rb.getString("cookies.cookies") + "<br>");
for (int i = 0; i < cookies.length; i++) {
Cookie cookie = cookies[i];
out.print("Cookie Name: " + cookie.getName() + "<br>");
out.println(" Cookie Value: " + cookie.getValue() +
"<br><br>");
}
} else {
out.println(rb.getString("cookies.no-cookies"));
}
String cookieName = request.getParameter("cookiename");
String cookieValue = request.getParameter("cookievalue");
if (cookieName != null && cookieValue != null) {
Cookie cookie = new Cookie(cookieName, cookieValue);
response.addCookie(cookie);
out.println("<P>");
out.println(rb.getString("cookies.set") + "<br>");
out.print(rb.getString("cookies.name") + " " + cookieName +
"<br>");
out.print(rb.getString("cookies.value") + " " + cookieValue);
}
out.println("<P>");
out.println(rb.getString("cookies.make-cookie") + "<br>");
out.print("<form action=\"");
out.println("CookieExample\" method=POST>");
out.print(rb.getString("cookies.name") + " ");
out.println("<input type=text length=20 name=cookiename><br>");
out.print(rb.getString("cookies.value") + " ");
out.println("<input type=text length=20 name=cookievalue><br>");
out.println("<input type=submit></form>");
out.println("</body>");
out.println("</html>");
}
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
doGet(request, response);
}
}
1.1 jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/HelloWorldExample.java
Index: HelloWorldExample.java
===================================================================
/* $Id: HelloWorldExample.java,v 1.1 2000/08/17 00:57:52 horwat Exp $
*
*/
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* The simplest possible servlet.
*
* @author James Duncan Davidson
*/
public class HelloWorldExample extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
ResourceBundle rb =
ResourceBundle.getBundle("LocalStrings",request.getLocale());
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
String title = rb.getString("helloworld.title");
out.println("<title>" + title + "</title>");
out.println("</head>");
out.println("<body bgcolor=\"white\">");
out.println("<body>");
// note that all links are created to be relative. this
// ensures that we can move the web application that this
// servlet belongs to to a different place in the url
// tree and not have any harmful side effects.
// XXX
// making these absolute till we work out the
// addition of a PathInfo issue
out.println("<a href=\"/examples/servlets/helloworld.html\">");
out.println("<img src=\"/examples/images/code.gif\" height=24 " +
"width=24 align=right border=0 alt=\"view code\"></a>");
out.println("<a href=\"/examples/servlets/index.html\">");
out.println("<img src=\"/examples/images/return.gif\" height=24 " +
"width=24 align=right border=0 alt=\"return\"></a>");
out.println("<h1>" + title + "</h1>");
out.println("</body>");
out.println("</html>");
}
}
1.1 jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/LocalStrings.properties
Index: LocalStrings.properties
===================================================================
# $Id: LocalStrings.properties,v 1.1 2000/08/17 00:57:52 horwat Exp $
# Default localized resources for example servlets
# This locale is en_US
helloworld.title=Hello World!
requestinfo.title=Request Information Example
requestinfo.label.method=Method:
requestinfo.label.requesturi=Request URI:
requestinfo.label.protocol=Protocol:
requestinfo.label.pathinfo=Path Info:
requestinfo.label.remoteaddr=Remote Address:
requestheader.title=Request Header Example
requestparams.title=Request Parameters Example
requestparams.params-in-req=Parameters in this request:
requestparams.no-params=No Parameters, Please enter some
requestparams.firstname=First Name:
requestparams.lastname=Last Name:
cookies.title=Cookies Example
cookies.cookies=Your browser is sending the following cookies:
cookies.no-cookies=Your browser isn't sending any cookies
cookies.make-cookie=Create a cookie to send to your browser
cookies.name=Name:
cookies.value=Value:
cookies.set=You just sent the following cookie to your browser:
sessions.title=Sessions Example
sessions.id=Session ID:
sessions.created=Created:
sessions.lastaccessed=Last Accessed:
sessions.data=The following data is in your session:
sessions.adddata=Add data to your session
sessions.dataname=Name of Session Attribute:
sessions.datavalue=Value of Session Attribute:
1.1 jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/LocalStrings_en.properties
Index: LocalStrings_en.properties
===================================================================
# $Id: LocalStrings_en.properties,v 1.1 2000/08/17 00:57:52 horwat Exp $
# Default localized resources for example servlets
# This locale is en_US
helloworld.title=Hello World!
requestinfo.title=Request Information Example
requestinfo.label.method=Method:
requestinfo.label.requesturi=Request URI:
requestinfo.label.protocol=Protocol:
requestinfo.label.pathinfo=Path Info:
requestinfo.label.remoteaddr=Remote Address:
requestheader.title=Request Header Example
requestparams.title=Request Parameters Example
requestparams.params-in-req=Parameters in this request:
requestparams.no-params=No Parameters, Please enter some
requestparams.firstname=First Name:
requestparams.lastname=Last Name:
cookies.title=Cookies Example
cookies.cookies=Your browser is sending the following cookies:
cookies.no-cookies=Your browser isn't sending any cookies
cookies.make-cookie=Create a cookie to send to your browser
cookies.name=Name:
cookies.value=Value:
cookies.set=You just sent the following cookie to your browser:
sessions.title=Sessions Example
sessions.id=Session ID:
sessions.created=Created:
sessions.lastaccessed=Last Accessed:
sessions.data=The following data is in your session:
sessions.adddata=Add data to your session
sessions.dataname=Name of Session Attribute:
sessions.datavalue=Value of Session Attribute:
1.1 jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/LocalStrings_es.properties
Index: LocalStrings_es.properties
===================================================================
# $Id: LocalStrings_es.properties,v 1.1 2000/08/17 00:57:53 horwat Exp $
#
# Default localized string information
# Localized para Locale es_ES
helloworld.title=Hola Mundo!
requestinfo.title=Ejemplo de Informacion de Request
requestinfo.label.method=Metodo:
requestinfo.label.requesturi=Request URI:
requestinfo.label.protocol=Protocolo:
requestinfo.label.pathinfo=Path Info:
requestinfo.label.remoteaddr=Direccion Remota:
requestheader.title=Ejemplo de Cabecera de Request
requestparams.title=Ejemplo de parametros de Request
requestparams.params-in-req=Parametros en este Request:
requestparams.no-params=No hay parametro. por favor usa alguno
requestparams.firstname=Nombre:
requestparams.lastname=Apellidos:
cookies.title=Ejemplo de Cookies
cookies.cookies=Tu navegador esta enviando los siguientes cookies:
cookies.no-cookies=Tu navegador no esta enviando cookies
cookies.make-cookie=Crea un cookie para enviarlo a tu navegador
cookies.name=Nombre:
cookies.value=Valor:
cookies.set=Acabas de enviar a tu navegador estos cookies:
sessions.title=ejemplo de Sesiones
sessions.id=ID de Sesion:
sessions.created=Creado:
sessions.lastaccessed=Ultimo Acceso:
sessions.data=Lo siguientes datos estan en tu sesion:
sessions.adddata=A�ade datos a tu sesion:
sessions.dataname=Nombre del atributo de sesion:
sessions.datavalue=Valor del atributo de sesion:
1.1 jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/RequestHeaderExample.java
Index: RequestHeaderExample.java
===================================================================
/* $Id: RequestHeaderExample.java,v 1.1 2000/08/17 00:57:53 horwat Exp $
*
*/
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* Example servlet showing request headers
*
* @author James Duncan Davidson <du...@eng.sun.com>
*/
public class RequestHeaderExample extends HttpServlet {
ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<body bgcolor=\"white\">");
out.println("<head>");
String title = rb.getString("requestheader.title");
out.println("<title>" + title + "</title>");
out.println("</head>");
out.println("<body>");
// all links relative
// XXX
// making these absolute till we work out the
// addition of a PathInfo issue
out.println("<a href=\"/examples/servlets/reqheaders.html\">");
out.println("<img src=\"/examples/images/code.gif\" height=24 " +
"width=24 align=right border=0 alt=\"view code\"></a>");
out.println("<a href=\"/examples/servlets/index.html\">");
out.println("<img src=\"/examples/images/return.gif\" height=24 " +
"width=24 align=right border=0 alt=\"return\"></a>");
out.println("<h3>" + title + "</h3>");
out.println("<table border=0>");
Enumeration e = request.getHeaderNames();
while (e.hasMoreElements()) {
String headerName = (String)e.nextElement();
String headerValue = request.getHeader(headerName);
out.println("<tr><td bgcolor=\"#CCCCCC\">" + headerName);
out.println("</td><td>" + headerValue + "</td></tr>");
}
out.println("</table>");
}
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
doGet(request, response);
}
}
1.1 jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/RequestInfoExample.java
Index: RequestInfoExample.java
===================================================================
/* $Id: RequestInfoExample.java,v 1.1 2000/08/17 00:57:53 horwat Exp $
*
*/
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* Example servlet showing request information.
*
* @author James Duncan Davidson <du...@eng.sun.com>
*/
public class RequestInfoExample extends HttpServlet {
ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<body>");
out.println("<head>");
String title = rb.getString("requestinfo.title");
out.println("<title>" + title + "</title>");
out.println("</head>");
out.println("<body bgcolor=\"white\">");
// img stuff not req'd for source code html showing
// all links relative!
// XXX
// making these absolute till we work out the
// addition of a PathInfo issue
out.println("<a href=\"/examples/servlets/reqinfo.html\">");
out.println("<img src=\"/examples/images/code.gif\" height=24 " +
"width=24 align=right border=0 alt=\"view code\"></a>");
out.println("<a href=\"/examples/servlets/index.html\">");
out.println("<img src=\"/examples/images/return.gif\" height=24 " +
"width=24 align=right border=0 alt=\"return\"></a>");
out.println("<h3>" + title + "</h3>");
out.println("<table border=0><tr><td>");
out.println(rb.getString("requestinfo.label.method"));
out.println("</td><td>");
out.println(request.getMethod());
out.println("</td></tr><tr><td>");
out.println(rb.getString("requestinfo.label.requesturi"));
out.println("</td><td>");
out.println(request.getRequestURI());
out.println("</td></tr><tr><td>");
out.println(rb.getString("requestinfo.label.protocol"));
out.println("</td><td>");
out.println(request.getProtocol());
out.println("</td></tr><tr><td>");
out.println(rb.getString("requestinfo.label.pathinfo"));
out.println("</td><td>");
out.println(request.getPathInfo());
out.println("</td></tr><tr><td>");
out.println(rb.getString("requestinfo.label.remoteaddr"));
out.println("</td><td>");
out.println(request.getRemoteAddr());
out.println("</table>");
}
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
doGet(request, response);
}
}
1.1 jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/RequestParamExample.java
Index: RequestParamExample.java
===================================================================
/* $Id: RequestParamExample.java,v 1.1 2000/08/17 00:57:53 horwat Exp $
*
*/
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* Example servlet showing request headers
*
* @author James Duncan Davidson <du...@eng.sun.com>
*/
public class RequestParamExample extends HttpServlet {
ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<body>");
out.println("<head>");
String title = rb.getString("requestparams.title");
out.println("<title>" + title + "</title>");
out.println("</head>");
out.println("<body bgcolor=\"white\">");
// img stuff not req'd for source code html showing
// all links relative
// XXX
// making these absolute till we work out the
// addition of a PathInfo issue
out.println("<a href=\"/examples/servlets/reqparams.html\">");
out.println("<img src=\"/examples/images/code.gif\" height=24 " +
"width=24 align=right border=0 alt=\"view code\"></a>");
out.println("<a href=\"/examples/servlets/index.html\">");
out.println("<img src=\"/examples/images/return.gif\" height=24 " +
"width=24 align=right border=0 alt=\"return\"></a>");
out.println("<h3>" + title + "</h3>");
String firstName = request.getParameter("firstname");
String lastName = request.getParameter("lastname");
out.println(rb.getString("requestparams.params-in-req") + "<br>");
if (firstName != null || lastName != null) {
out.println(rb.getString("requestparams.firstname"));
out.println(" = " + firstName + "<br>");
out.println(rb.getString("requestparams.lastname"));
out.println(" = " + lastName);
} else {
out.println(rb.getString("requestparams.no-params"));
}
out.println("<P>");
out.print("<form action=\"");
out.print("RequestParamExample\" ");
out.println("method=POST>");
out.println(rb.getString("requestparams.firstname"));
out.println("<input type=text size=20 name=firstname>");
out.println("<br>");
out.println(rb.getString("requestparams.lastname"));
out.println("<input type=text size=20 name=lastname>");
out.println("<br>");
out.println("<input type=submit>");
out.println("</form>");
out.println("</body>");
out.println("</html>");
}
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
doGet(request, response);
}
}
1.1 jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/SessionExample.java
Index: SessionExample.java
===================================================================
/* $Id: SessionExample.java,v 1.1 2000/08/17 00:57:53 horwat Exp $
*
*/
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* Example servlet showing request headers
*
* @author James Duncan Davidson <du...@eng.sun.com>
*/
public class SessionExample extends HttpServlet {
ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<body bgcolor=\"white\">");
out.println("<head>");
String title = rb.getString("sessions.title");
out.println("<title>" + title + "</title>");
out.println("</head>");
out.println("<body>");
// img stuff not req'd for source code html showing
// relative links everywhere!
// XXX
// making these absolute till we work out the
// addition of a PathInfo issue
out.println("<a href=\"/examples/servlets/sessions.html\">");
out.println("<img src=\"/examples/images/code.gif\" height=24 " +
"width=24 align=right border=0 alt=\"view code\"></a>");
out.println("<a href=\"/examples/servlets/index.html\">");
out.println("<img src=\"/examples/images/return.gif\" height=24 " +
"width=24 align=right border=0 alt=\"return\"></a>");
out.println("<h3>" + title + "</h3>");
HttpSession session = request.getSession();
out.println(rb.getString("sessions.id") + " " + session.getId());
out.println("<br>");
out.println(rb.getString("sessions.created") + " ");
out.println(new Date(session.getCreationTime()) + "<br>");
out.println(rb.getString("sessions.lastaccessed") + " ");
out.println(new Date(session.getLastAccessedTime()));
String dataName = request.getParameter("dataname");
String dataValue = request.getParameter("datavalue");
if (dataName != null && dataValue != null) {
session.setAttribute(dataName, dataValue);
}
out.println("<P>");
out.println(rb.getString("sessions.data") + "<br>");
Enumeration names = session.getAttributeNames();
while (names.hasMoreElements()) {
String name = (String) names.nextElement();
String value = session.getAttribute(name).toString();
out.println(name + " = " + value + "<br>");
}
out.println("<P>");
out.print("<form action=\"");
out.print(response.encodeURL("SessionExample"));
out.print("\" ");
out.println("method=POST>");
out.println(rb.getString("sessions.dataname"));
out.println("<input type=text size=20 name=dataname>");
out.println("<br>");
out.println(rb.getString("sessions.datavalue"));
out.println("<input type=text size=20 name=datavalue>");
out.println("<br>");
out.println("<input type=submit>");
out.println("</form>");
out.println("<P>GET based form:<br>");
out.print("<form action=\"");
out.print(response.encodeURL("SessionExample"));
out.print("\" ");
out.println("method=GET>");
out.println(rb.getString("sessions.dataname"));
out.println("<input type=text size=20 name=dataname>");
out.println("<br>");
out.println(rb.getString("sessions.datavalue"));
out.println("<input type=text size=20 name=datavalue>");
out.println("<br>");
out.println("<input type=submit>");
out.println("</form>");
out.print("<p><a href=\"");
out.print(response.encodeURL("SessionExample?dataname=foo&datavalue=bar"));
out.println("\" >URL encoded </a>");
out.println("</body>");
out.println("</html>");
out.println("</body>");
out.println("</html>");
}
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
doGet(request, response);
}
}
1.1 jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/SnoopServlet.java
Index: SnoopServlet.java
===================================================================
/* $Id: SnoopServlet.java,v 1.1 2000/08/17 00:57:53 horwat Exp $
*
*/
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import javax.servlet.*;
import javax.servlet.http.*;
/**
*
*
* @author James Duncan Davidson <du...@eng.sun.com>
* @author Jason Hunter <jc...@eng.sun.com>
*/
public class SnoopServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
PrintWriter out = response.getWriter();
response.setContentType("text/plain");
out.println("Snoop Servlet");
out.println();
out.println("Servlet init parameters:");
Enumeration e = getInitParameterNames();
while (e.hasMoreElements()) {
String key = (String)e.nextElement();
String value = getInitParameter(key);
out.println(" " + key + " = " + value);
}
out.println();
out.println("Context init parameters:");
ServletContext context = getServletContext();
Enumeration enum = context.getInitParameterNames();
while (enum.hasMoreElements()) {
String key = (String)enum.nextElement();
Object value = context.getInitParameter(key);
out.println(" " + key + " = " + value);
}
out.println();
out.println("Context attributes:");
enum = context.getAttributeNames();
while (enum.hasMoreElements()) {
String key = (String)enum.nextElement();
Object value = context.getAttribute(key);
out.println(" " + key + " = " + value);
}
out.println();
out.println("Request attributes:");
e = request.getAttributeNames();
while (e.hasMoreElements()) {
String key = (String)e.nextElement();
Object value = request.getAttribute(key);
out.println(" " + key + " = " + value);
}
out.println();
out.println("Servlet Name: " + getServletName());
out.println("Protocol: " + request.getProtocol());
out.println("Scheme: " + request.getScheme());
out.println("Server Name: " + request.getServerName());
out.println("Server Port: " + request.getServerPort());
out.println("Server Info: " + context.getServerInfo());
out.println("Remote Addr: " + request.getRemoteAddr());
out.println("Remote Host: " + request.getRemoteHost());
out.println("Character Encoding: " + request.getCharacterEncoding());
out.println("Content Length: " + request.getContentLength());
out.println("Content Type: "+ request.getContentType());
out.println("Locale: "+ request.getLocale());
out.println("Default Response Buffer: "+ response.getBufferSize());
out.println();
out.println("Parameter names in this request:");
e = request.getParameterNames();
while (e.hasMoreElements()) {
String key = (String)e.nextElement();
String[] values = request.getParameterValues(key);
out.print(" " + key + " = ");
for(int i = 0; i < values.length; i++) {
out.print(values[i] + " ");
}
out.println();
}
out.println();
out.println("Headers in this request:");
e = request.getHeaderNames();
while (e.hasMoreElements()) {
String key = (String)e.nextElement();
String value = request.getHeader(key);
out.println(" " + key + ": " + value);
}
out.println();
out.println("Cookies in this request:");
Cookie[] cookies = request.getCookies();
for (int i = 0; i < cookies.length; i++) {
Cookie cookie = cookies[i];
out.println(" " + cookie.getName() + " = " + cookie.getValue());
}
out.println();
out.println("Request Is Secure: " + request.isSecure());
out.println("Auth Type: " + request.getAuthType());
out.println("HTTP Method: " + request.getMethod());
out.println("Remote User: " + request.getRemoteUser());
out.println("Request URI: " + request.getRequestURI());
out.println("Context Path: " + request.getContextPath());
out.println("Servlet Path: " + request.getServletPath());
out.println("Path Info: " + request.getPathInfo());
out.println("Path Trans: " + request.getPathTranslated());
out.println("Query String: " + request.getQueryString());
out.println();
HttpSession session = request.getSession();
out.println("Requested Session Id: " +
request.getRequestedSessionId());
out.println("Current Session Id: " + session.getId());
out.println("Session Created Time: " + session.getCreationTime());
out.println("Session Last Accessed Time: " +
session.getLastAccessedTime());
out.println("Session Max Inactive Interval Seconds: " +
session.getMaxInactiveInterval());
out.println();
out.println("Session values: ");
Enumeration names = session.getAttributeNames();
while (names.hasMoreElements()) {
String name = (String) names.nextElement();
out.println(" " + name + " = " + session.getAttribute(name));
}
}
}
1.1 jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/servletToJsp.java
Index: servletToJsp.java
===================================================================
import javax.servlet.*;
import javax.servlet.http.*;
public class servletToJsp extends HttpServlet {
public void doGet (HttpServletRequest request,
HttpServletResponse response) {
try {
// Set the attribute and Forward to hello.jsp
request.setAttribute ("servletName", "servletToJsp");
getServletConfig().getServletContext().getRequestDispatcher("/jsp/jsptoserv/hello.jsp").forward(request, response);
} catch (Exception ex) {
ex.printStackTrace ();
}
}
}
1.1 jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/cal/Entries.java
Index: Entries.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package cal;
import java.util.Enumeration;
import java.util.Hashtable;
import javax.servlet.http.*;
public class Entries {
private Hashtable entries;
private static final String[] time = {"8am", "9am", "10am", "11am", "12pm",
"1pm", "2pm", "3pm", "4pm", "5pm", "6pm",
"7pm", "8pm" };
public static final int rows = 12;
public Entries () {
entries = new Hashtable (rows);
for (int i=0; i < rows; i++) {
entries.put (time[i], new Entry(time[i]));
}
}
public int getRows () {
return rows;
}
public Entry getEntry (int index) {
return (Entry)this.entries.get(time[index]);
}
public int getIndex (String tm) {
for (int i=0; i<rows; i++)
if(tm.equals(time[i])) return i;
return -1;
}
public void processRequest (HttpServletRequest request, String tm) {
int index = getIndex (tm);
if (index >= 0) {
String descr = request.getParameter ("description");
((Entry)entries.get(time[index])).setDescription (descr);
}
}
}
1.1 jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/cal/Entry.java
Index: Entry.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package cal;
public class Entry {
String hour;
String description;
String color;
public Entry (String hour) {
this.hour = hour;
this.description = "";
}
public String getHour () {
return this.hour;
}
public String getColor () {
if (description.equals("")) return "lightblue";
else return "red";
}
public String getDescription () {
if (description.equals("")) return "None";
else return this.description;
}
public void setDescription (String descr) {
description = descr;
}
}
1.1 jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/cal/JspCalendar.java
Index: JspCalendar.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package cal;
import java.text.DateFormat;
import java.util.*;
public class JspCalendar {
Calendar calendar = null;
Date currentDate;
public JspCalendar() {
calendar = Calendar.getInstance();
Date trialTime = new Date();
calendar.setTime(trialTime);
}
public int getYear() {
return calendar.get(Calendar.YEAR);
}
public String getMonth() {
int m = getMonthInt();
String[] months = new String [] { "January", "February", "March",
"April", "May", "June",
"July", "August", "September",
"October", "November", "December" };
if (m > 12)
return "Unknown to Man";
return months[m - 1];
}
public String getDay() {
int x = getDayOfWeek();
String[] days = new String[] {"Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"};
if (x > 7)
return "Unknown to Man";
return days[x - 1];
}
public int getMonthInt() {
return 1 + calendar.get(Calendar.MONTH);
}
public String getDate() {
return getMonthInt() + "/" + getDayOfMonth() + "/" + getYear();
}
public String getCurrentDate() {
Date dt = new Date ();
calendar.setTime (dt);
return getMonthInt() + "/" + getDayOfMonth() + "/" + getYear();
}
public String getNextDate() {
calendar.set (Calendar.DAY_OF_MONTH, getDayOfMonth() + 1);
return getDate ();
}
public String getPrevDate() {
calendar.set (Calendar.DAY_OF_MONTH, getDayOfMonth() - 1);
return getDate ();
}
public String getTime() {
return getHour() + ":" + getMinute() + ":" + getSecond();
}
public int getDayOfMonth() {
return calendar.get(Calendar.DAY_OF_MONTH);
}
public int getDayOfYear() {
return calendar.get(Calendar.DAY_OF_YEAR);
}
public int getWeekOfYear() {
return calendar.get(Calendar.WEEK_OF_YEAR);
}
public int getWeekOfMonth() {
return calendar.get(Calendar.WEEK_OF_MONTH);
}
public int getDayOfWeek() {
return calendar.get(Calendar.DAY_OF_WEEK);
}
public int getHour() {
return calendar.get(Calendar.HOUR_OF_DAY);
}
public int getMinute() {
return calendar.get(Calendar.MINUTE);
}
public int getSecond() {
return calendar.get(Calendar.SECOND);
}
public int getEra() {
return calendar.get(Calendar.ERA);
}
public String getUSTimeZone() {
String[] zones = new String[] {"Hawaii", "Alaskan", "Pacific",
"Mountain", "Central", "Eastern"};
return zones[10 + getZoneOffset()];
}
public int getZoneOffset() {
return calendar.get(Calendar.ZONE_OFFSET)/(60*60*1000);
}
public int getDSTOffset() {
return calendar.get(Calendar.DST_OFFSET)/(60*60*1000);
}
public int getAMPM() {
return calendar.get(Calendar.AM_PM);
}
}
1.1 jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/cal/TableBean.java
Index: TableBean.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package cal;
import java.beans.*;
import javax.servlet.http.*;
import javax.servlet.*;
import java.util.Hashtable;
public class TableBean {
Hashtable table;
JspCalendar JspCal;
Entries entries;
String date;
String name = null;
String email = null;
boolean processError = false;
public TableBean () {
this.table = new Hashtable (10);
this.JspCal = new JspCalendar ();
this.date = JspCal.getCurrentDate ();
}
public void setName (String nm) {
this.name = nm;
}
public String getName () {
return this.name;
}
public void setEmail (String mail) {
this.email = mail;
}
public String getEmail () {
return this.email;
}
public String getDate () {
return this.date;
}
public Entries getEntries () {
return this.entries;
}
public void processRequest (HttpServletRequest request) {
// Get the name and e-mail.
this.processError = false;
if (name == null || name.equals("")) setName(request.getParameter ("name"));
if (email == null || email.equals("")) setEmail(request.getParameter ("email"));
if (name == null || email == null ||
name.equals("") || email.equals("")) {
this.processError = true;
return;
}
// Get the date.
String dateR = request.getParameter ("date");
if (dateR == null) date = JspCal.getCurrentDate ();
else if (dateR.equalsIgnoreCase("next")) date = JspCal.getNextDate ();
else if (dateR.equalsIgnoreCase("prev")) date = JspCal.getPrevDate ();
entries = (Entries) table.get (date);
if (entries == null) {
entries = new Entries ();
table.put (date, entries);
}
// If time is provided add the event.
String time = request.getParameter("time");
if (time != null) entries.processRequest (request, time);
}
public boolean getProcessError () {
return this.processError;
}
}
1.1 jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/checkbox/CheckTest.java
Index: CheckTest.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package checkbox;
public class CheckTest {
String b[] = new String[] { "1", "2", "3", "4" };
public String[] getFruit() {
return b;
}
public void setFruit(String [] b) {
this.b = b;
}
}
1.1 jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/colors/ColorGameBean.java
Index: ColorGameBean.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package colors;
import javax.servlet.http.*;
public class ColorGameBean {
private String background = "yellow";
private String foreground = "red";
private String color1 = foreground;
private String color2 = background;
private String hint = "no";
private int attempts = 0;
private int intval = 0;
private boolean tookHints = false;
public void processRequest(HttpServletRequest request) {
// background = "yellow";
// foreground = "red";
if (! color1.equals(foreground)) {
if (color1.equalsIgnoreCase("black") ||
color1.equalsIgnoreCase("cyan")) {
background = color1;
}
}
if (! color2.equals(background)) {
if (color2.equalsIgnoreCase("black") ||
color2.equalsIgnoreCase("cyan")) {
foreground = color2;
}
}
attempts++;
}
public void setColor2(String x) {
color2 = x;
}
public void setColor1(String x) {
color1 = x;
}
public void setAction(String x) {
if (!tookHints)
tookHints = x.equalsIgnoreCase("Hint");
hint = x;
}
public String getColor2() {
return background;
}
public String getColor1() {
return foreground;
}
public int getAttempts() {
return attempts;
}
public boolean getHint() {
return hint.equalsIgnoreCase("Hint");
}
public boolean getSuccess() {
if (background.equalsIgnoreCase("black") ||
background.equalsIgnoreCase("cyan")) {
if (foreground.equalsIgnoreCase("black") ||
foreground.equalsIgnoreCase("cyan"))
return true;
else
return false;
}
return false;
}
public boolean getHintTaken() {
return tookHints;
}
public void reset() {
foreground = "red";
background = "yellow";
}
public void setIntval(int value) {
intval = value;
}
public int getIntval() {
return intval;
}
}
1.1 jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/dates/JspCalendar.java
Index: JspCalendar.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package dates;
import java.text.DateFormat;
import java.util.*;
public class JspCalendar {
Calendar calendar = null;
public JspCalendar() {
calendar = Calendar.getInstance();
Date trialTime = new Date();
calendar.setTime(trialTime);
}
public int getYear() {
return calendar.get(Calendar.YEAR);
}
public String getMonth() {
int m = getMonthInt();
String[] months = new String [] { "January", "February", "March",
"April", "May", "June",
"July", "August", "September",
"October", "November", "December" };
if (m > 12)
return "Unknown to Man";
return months[m - 1];
}
public String getDay() {
int x = getDayOfWeek();
String[] days = new String[] {"Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"};
if (x > 7)
return "Unknown to Man";
return days[x - 1];
}
public int getMonthInt() {
return 1 + calendar.get(Calendar.MONTH);
}
public String getDate() {
return getMonthInt() + "/" + getDayOfMonth() + "/" + getYear();
}
public String getTime() {
return getHour() + ":" + getMinute() + ":" + getSecond();
}
public int getDayOfMonth() {
return calendar.get(Calendar.DAY_OF_MONTH);
}
public int getDayOfYear() {
return calendar.get(Calendar.DAY_OF_YEAR);
}
public int getWeekOfYear() {
return calendar.get(Calendar.WEEK_OF_YEAR);
}
public int getWeekOfMonth() {
return calendar.get(Calendar.WEEK_OF_MONTH);
}
public int getDayOfWeek() {
return calendar.get(Calendar.DAY_OF_WEEK);
}
public int getHour() {
return calendar.get(Calendar.HOUR_OF_DAY);
}
public int getMinute() {
return calendar.get(Calendar.MINUTE);
}
public int getSecond() {
return calendar.get(Calendar.SECOND);
}
public static void main(String args[]) {
JspCalendar db = new JspCalendar();
p("date: " + db.getDayOfMonth());
p("year: " + db.getYear());
p("month: " + db.getMonth());
p("time: " + db.getTime());
p("date: " + db.getDate());
p("Day: " + db.getDay());
p("DayOfYear: " + db.getDayOfYear());
p("WeekOfYear: " + db.getWeekOfYear());
p("era: " + db.getEra());
p("ampm: " + db.getAMPM());
p("DST: " + db.getDSTOffset());
p("ZONE Offset: " + db.getZoneOffset());
p("TIMEZONE: " + db.getUSTimeZone());
}
private static void p(String x) {
System.out.println(x);
}
public int getEra() {
return calendar.get(Calendar.ERA);
}
public String getUSTimeZone() {
String[] zones = new String[] {"Hawaii", "Alaskan", "Pacific",
"Mountain", "Central", "Eastern"};
return zones[10 + getZoneOffset()];
}
public int getZoneOffset() {
return calendar.get(Calendar.ZONE_OFFSET)/(60*60*1000);
}
public int getDSTOffset() {
return calendar.get(Calendar.DST_OFFSET)/(60*60*1000);
}
public int getAMPM() {
return calendar.get(Calendar.AM_PM);
}
}
1.1 jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/error/Smart.java
Index: Smart.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package error;
import java.io.*;
import java.lang.*;
public class Smart {
String name = "JSP";
public String getName () {
return name;
}
public void setName (String name) {
this.name = name;
}
}
1.1 jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/examples/ExampleTagBase.java
Index: ExampleTagBase.java
===================================================================
package examples;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
public abstract class ExampleTagBase implements Tag {
public void setParent(Tag parent) {
this.parent = parent;
}
public void setBodyContent(BodyContent bodyOut) {
this.bodyOut = bodyOut;
}
public void setPageContext(PageContext pageContext) {
this.pageContext = pageContext;
}
public Tag getParent() {
return this.parent;
}
public int doStartTag() throws JspException {
return SKIP_BODY;
}
public int doEndTag() throws JspException {
return EVAL_PAGE;
}
// Default implementations for BodyTag methods as well
// just in case a tag decides to implement BodyTag.
public void doInitBody() throws JspException {
}
public int doAfterBody() throws JspException {
return SKIP_BODY;
}
public void release() {
bodyOut = null;
pageContext = null;
parent = null;
}
protected BodyContent bodyOut;
protected PageContext pageContext;
protected Tag parent;
}
1.1 jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/examples/FooTag.java
Index: FooTag.java
===================================================================
package examples;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.util.Hashtable;
import java.io.Writer;
import java.io.IOException;
/**
* Example1: the simplest tag
* Collect attributes and call into some actions
*
* <foo att1="..." att2="...." att3="...." />
*/
public class FooTag
extends ExampleTagBase
implements BodyTag
{
private String atts[] = new String[3];
int i = 0;
private final void setAtt(int index, String value) {
atts[index] = value;
}
public void setAtt1(String value) {
setAtt(0, value);
}
public void setAtt2(String value) {
setAtt(1, value);
}
public void setAtt3(String value) {
setAtt(2, value);
}
/**
* Process start tag
*
* @return EVAL_BODY_INCLUDE
*/
public int doStartTag() throws JspException {
return EVAL_BODY_TAG;
}
public void doInitBody() throws JspException {
pageContext.setAttribute("member", atts[i]);
i++;
}
public int doAfterBody() throws JspException {
try {
if (i == 3) {
bodyOut.writeOut(bodyOut.getEnclosingWriter());
return SKIP_BODY;
} else
pageContext.setAttribute("member", atts[i]);
i++;
return EVAL_BODY_TAG;
} catch (IOException ex) {
throw new JspTagException(ex.toString());
}
}
}
1.1 jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/examples/FooTagExtraInfo.java
Index: FooTagExtraInfo.java
===================================================================
package examples;
import javax.servlet.jsp.tagext.*;
public class FooTagExtraInfo extends TagExtraInfo {
public VariableInfo[] getVariableInfo(TagData data) {
return new VariableInfo[]
{
new VariableInfo("member",
"String",
true,
VariableInfo.NESTED)
};
}
}
1.1 jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/examples/LogTag.java
Index: LogTag.java
===================================================================
package examples;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.io.IOException;
/**
* Log the contents of the body. Could be used to handle errors etc.
*/
public class LogTag
extends ExampleTagBase
implements BodyTag
{
boolean toBrowser = false;
public void setToBrowser(String value) {
if (value == null)
toBrowser = false;
else if (value.equalsIgnoreCase("true"))
toBrowser = true;
else
toBrowser = false;
}
public int doStartTag() throws JspException {
return EVAL_BODY_TAG;
}
public int doAfterBody() throws JspException {
try {
String s = bodyOut.getString();
System.err.println(s);
if (toBrowser)
bodyOut.writeOut(bodyOut.getEnclosingWriter());
return SKIP_BODY;
} catch (IOException ex) {
throw new JspTagException(ex.toString());
}
}
}
1.1 jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/examples/ShowSource.java
Index: ShowSource.java
===================================================================
package examples;
import javax.servlet.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.io.*;
/**
* Display the sources of the JSP file.
*/
public class ShowSource
extends TagSupport
{
String jspFile;
public void setJspFile(String jspFile) {
this.jspFile = jspFile;
}
public int doEndTag() throws JspException {
if (jspFile.indexOf( ".." ) >= 0)
throw new JspTagException("Invalid JSP file " + jspFile);
InputStream in
= pageContext.getServletContext().getResourceAsStream(jspFile);
if (in == null)
throw new JspTagException("Unable to find JSP file: "+jspFile);
InputStreamReader reader = new InputStreamReader(in);
JspWriter out = pageContext.getOut();
try {
out.println("<body>");
out.println("<pre>");
for(int ch = in.read(); ch != -1; ch = in.read())
if (ch == '<')
out.print("<");
else
out.print((char) ch);
out.println("</pre>");
out.println("</body>");
} catch (IOException ex) {
throw new JspTagException("IOException: "+ex.toString());
}
return super.doEndTag();
}
}
1.1 jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/num/NumberGuessBean.java
Index: NumberGuessBean.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
/*
* Originally written by Jason Hunter, http://www.servlets.com.
*/
package num;
import java.util.*;
public class NumberGuessBean {
int answer;
boolean success;
String hint;
int numGuesses;
public NumberGuessBean() {
reset();
}
public void setGuess(String guess) {
numGuesses++;
int g;
try {
g = Integer.parseInt(guess);
}
catch (NumberFormatException e) {
g = -1;
}
if (g == answer) {
success = true;
}
else if (g == -1) {
hint = "a number next time";
}
else if (g < answer) {
hint = "higher";
}
else if (g > answer) {
hint = "lower";
}
}
public boolean getSuccess() {
return success;
}
public String getHint() {
return "" + hint;
}
public int getNumGuesses() {
return numGuesses;
}
public void reset() {
answer = Math.abs(new Random().nextInt() % 100) + 1;
success = false;
numGuesses = 0;
}
}
1.1 jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/sessions/DummyCart.java
Index: DummyCart.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package sessions;
import javax.servlet.http.*;
import java.util.Vector;
import java.util.Enumeration;
public class DummyCart {
Vector v = new Vector();
String submit = null;
String item = null;
private void addItem(String name) {
v.addElement(name);
}
private void removeItem(String name) {
v.removeElement(name);
}
public void setItem(String name) {
item = name;
}
public void setSubmit(String s) {
submit = s;
}
public String[] getItems() {
String[] s = new String[v.size()];
v.copyInto(s);
return s;
}
public void processRequest(HttpServletRequest request) {
// null value for submit - user hit enter instead of clicking on
// "add" or "remove"
if (submit == null)
addItem(item);
if (submit.equals("add"))
addItem(item);
else if (submit.equals("remove"))
removeItem(item);
// reset at the end of the request
reset();
}
// reset
private void reset() {
submit = null;
item = null;
}
}
1.1 jakarta-tomcat-4.0/webapps/examples/WEB-INF/jsp/example-taglib.tld
Index: example-taglib.tld
===================================================================
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
"http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<!-- a tag library descriptor -->
<taglib>
<!-- after this the default space is
"http://java.sun.com/j2ee/dtds/jsptaglibrary_1_2.dtd"
-->
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>simple</shortname>
<uri></uri>
<info>
A simple tab library for the examples
</info>
<tag>
<name>ShowSource</name>
<tagclass>examples.ShowSource</tagclass>
<info> Display JSP sources </info>
<attribute>
<name>jspFile</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<!-- A simple Tag -->
<!-- foo tag -->
<tag>
<name>foo</name>
<tagclass>examples.FooTag</tagclass>
<teiclass>examples.FooTagExtraInfo</teiclass>
<bodycontent>JSP</bodycontent>
<info>
Perform a server side action; uses 3 mandatory attributes
</info>
<attribute>
<name>att1</name>
<required>true</required>
</attribute>
<attribute>
<name>att2</name>
<required>true</required>
</attribute>
<attribute>
<name>att3</name>
<required>true</required>
</attribute>
</tag>
<!-- Another simple tag -->
<!-- log tag -->
<tag>
<name>log</name>
<tagclass>examples.LogTag</tagclass>
<bodycontent>TAGDEPENDENT</bodycontent>
<info>
Perform a server side action; Log the message.
</info>
<attribute>
<name>toBrowser</name>
<required>false</required>
</attribute>
</tag>
</taglib>
1.1 jakarta-tomcat-4.0/webapps/examples/WEB-INF/jsp/applet/Clock2.java
Index: Clock2.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
import java.util.*;
import java.awt.*;
import java.applet.*;
import java.text.*;
/**
* Time!
*
* @author Rachel Gollub
*/
public class Clock2 extends Applet implements Runnable {
Thread timer; // The thread that displays clock
int lastxs, lastys, lastxm,
lastym, lastxh, lastyh; // Dimensions used to draw hands
SimpleDateFormat formatter; // Formats the date displayed
String lastdate; // String to hold date displayed
Font clockFaceFont; // Font for number display on clock
Date currentDate; // Used to get date to display
Color handColor; // Color of main hands and dial
Color numberColor; // Color of second hand and numbers
public void init() {
int x,y;
lastxs = lastys = lastxm = lastym = lastxh = lastyh = 0;
formatter = new SimpleDateFormat ("EEE MMM dd hh:mm:ss yyyy", Locale.getDefault());
currentDate = new Date();
lastdate = formatter.format(currentDate);
clockFaceFont = new Font("Serif", Font.PLAIN, 14);
handColor = Color.blue;
numberColor = Color.darkGray;
try {
setBackground(new Color(Integer.parseInt(getParameter("bgcolor"),16)));
} catch (Exception E) { }
try {
handColor = new Color(Integer.parseInt(getParameter("fgcolor1"),16));
} catch (Exception E) { }
try {
numberColor = new Color(Integer.parseInt(getParameter("fgcolor2"),16));
} catch (Exception E) { }
resize(300,300); // Set clock window size
}
// Plotpoints allows calculation to only cover 45 degrees of the circle,
// and then mirror
public void plotpoints(int x0, int y0, int x, int y, Graphics g) {
g.drawLine(x0+x,y0+y,x0+x,y0+y);
g.drawLine(x0+y,y0+x,x0+y,y0+x);
g.drawLine(x0+y,y0-x,x0+y,y0-x);
g.drawLine(x0+x,y0-y,x0+x,y0-y);
g.drawLine(x0-x,y0-y,x0-x,y0-y);
g.drawLine(x0-y,y0-x,x0-y,y0-x);
g.drawLine(x0-y,y0+x,x0-y,y0+x);
g.drawLine(x0-x,y0+y,x0-x,y0+y);
}
// Circle is just Bresenham's algorithm for a scan converted circle
public void circle(int x0, int y0, int r, Graphics g) {
int x,y;
float d;
x=0;
y=r;
d=5/4-r;
plotpoints(x0,y0,x,y,g);
while (y>x){
if (d<0) {
d=d+2*x+3;
x++;
}
else {
d=d+2*(x-y)+5;
x++;
y--;
}
plotpoints(x0,y0,x,y,g);
}
}
// Paint is the main part of the program
public void paint(Graphics g) {
int xh, yh, xm, ym, xs, ys, s = 0, m = 10, h = 10, xcenter, ycenter;
String today;
currentDate = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("s",Locale.getDefault());
try {
s = Integer.parseInt(formatter.format(currentDate));
} catch (NumberFormatException n) {
s = 0;
}
formatter.applyPattern("m");
try {
m = Integer.parseInt(formatter.format(currentDate));
} catch (NumberFormatException n) {
m = 10;
}
formatter.applyPattern("h");
try {
h = Integer.parseInt(formatter.format(currentDate));
} catch (NumberFormatException n) {
h = 10;
}
formatter.applyPattern("EEE MMM dd HH:mm:ss yyyy");
today = formatter.format(currentDate);
xcenter=80;
ycenter=55;
// a= s* pi/2 - pi/2 (to switch 0,0 from 3:00 to 12:00)
// x = r(cos a) + xcenter, y = r(sin a) + ycenter
xs = (int)(Math.cos(s * 3.14f/30 - 3.14f/2) * 45 + xcenter);
ys = (int)(Math.sin(s * 3.14f/30 - 3.14f/2) * 45 + ycenter);
xm = (int)(Math.cos(m * 3.14f/30 - 3.14f/2) * 40 + xcenter);
ym = (int)(Math.sin(m * 3.14f/30 - 3.14f/2) * 40 + ycenter);
xh = (int)(Math.cos((h*30 + m/2) * 3.14f/180 - 3.14f/2) * 30 + xcenter);
yh = (int)(Math.sin((h*30 + m/2) * 3.14f/180 - 3.14f/2) * 30 + ycenter);
// Draw the circle and numbers
g.setFont(clockFaceFont);
g.setColor(handColor);
circle(xcenter,ycenter,50,g);
g.setColor(numberColor);
g.drawString("9",xcenter-45,ycenter+3);
g.drawString("3",xcenter+40,ycenter+3);
g.drawString("12",xcenter-5,ycenter-37);
g.drawString("6",xcenter-3,ycenter+45);
// Erase if necessary, and redraw
g.setColor(getBackground());
if (xs != lastxs || ys != lastys) {
g.drawLine(xcenter, ycenter, lastxs, lastys);
g.drawString(lastdate, 5, 125);
}
if (xm != lastxm || ym != lastym) {
g.drawLine(xcenter, ycenter-1, lastxm, lastym);
g.drawLine(xcenter-1, ycenter, lastxm, lastym); }
if (xh != lastxh || yh != lastyh) {
g.drawLine(xcenter, ycenter-1, lastxh, lastyh);
g.drawLine(xcenter-1, ycenter, lastxh, lastyh); }
g.setColor(numberColor);
g.drawString("", 5, 125);
g.drawString(today, 5, 125);
g.drawLine(xcenter, ycenter, xs, ys);
g.setColor(handColor);
g.drawLine(xcenter, ycenter-1, xm, ym);
g.drawLine(xcenter-1, ycenter, xm, ym);
g.drawLine(xcenter, ycenter-1, xh, yh);
g.drawLine(xcenter-1, ycenter, xh, yh);
lastxs=xs; lastys=ys;
lastxm=xm; lastym=ym;
lastxh=xh; lastyh=yh;
lastdate = today;
currentDate=null;
}
public void start() {
timer = new Thread(this);
timer.start();
}
public void stop() {
timer = null;
}
public void run() {
Thread me = Thread.currentThread();
while (timer == me) {
try {
Thread.currentThread().sleep(100);
} catch (InterruptedException e) {
}
repaint();
}
}
public void update(Graphics g) {
paint(g);
}
public String getAppletInfo() {
return "Title: A Clock \nAuthor: Rachel Gollub, 1995 \nAn analog clock.";
}
public String[][] getParameterInfo() {
String[][] info = {
{"bgcolor", "hexadecimal RGB number", "The background color. Default is the color of your browser."},
{"fgcolor1", "hexadecimal RGB number", "The color of the hands and dial. Default is blue."},
{"fgcolor2", "hexadecimal RGB number", "The color of the seconds hand and numbers. Default is dark gray."}
};
return info;
}
}
1.1 jakarta-tomcat-4.0/webapps/examples/images/code.gif
<<Binary file>>
1.1 jakarta-tomcat-4.0/webapps/examples/images/execute.gif
<<Binary file>>
1.1 jakarta-tomcat-4.0/webapps/examples/images/return.gif
<<Binary file>>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/index.html
Index: index.html
===================================================================
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Mozilla/4.61 [en] (WinNT; I) [Netscape]">
<meta name="Author" content="Anil K. Vijendran">
<title>JSP Examples</title>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
</head>
<body bgcolor="#FFFFFF">
<b><font face="Arial, Helvetica, sans-serif"><font size=+2>JSP
Samples</font></font></b>
<p>This is a collection of samples demonstrates the usage of different
parts of the Java Server Pages (JSP) specification.
<p>These examples will only work when these pages are being served by the
ServletRunner. They will not work if you are viewing these pages via a
"file://..." URL.
<p>To navigate your way through the examples, the following icons will
help:
<br>
<table BORDER=0 CELLSPACING=5 WIDTH="85%" >
<tr VALIGN=TOP>
<td WIDTH="30"><img SRC="../images/execute.gif" ></td>
<td>Execute the example</td>
</tr>
<tr VALIGN=TOP>
<td WIDTH="30"><img SRC="../images/code.gif" height=24 width=24></td>
<td>Look at the source code for the example</td>
</tr>
<tr VALIGN=TOP>
<td WIDTH="30"><img SRC="../images/return.gif" height=24 width=24></td>
<td>Return to this screen</td>
</tr>
</table>
<p>Tip: For session scoped beans to work, the cookies must be enabled.
This can be done using browser options.
<br>
<table BORDER=0 CELLSPACING=5 WIDTH="85%" >
<tr VALIGN=TOP>
<td>Numberguess </td>
<td VALIGN=TOP WIDTH="30%"><a href="num/numguess.jsp"><img SRC="../images/execute.gif" HSPACE=4 BORDER=0 align=TOP></a><a href="num/numguess.jsp">Execute</a></td>
<td WIDTH="30%"><a href="num/numguess.html"><img SRC="../images/code.gif" HSPACE=4 BORDER=0 height=24 width=24 align=TOP></a><a href="num/numguess.html">Source</a></td>
</tr>
<tr VALIGN=TOP>
<td>Date </td>
<td VALIGN=TOP WIDTH="30%"><a href="dates/date.jsp"><img SRC="../images/execute.gif" HSPACE=4 BORDER=0 align=TOP></a><a href="dates/date.jsp">Execute</a></td>
<td WIDTH="30%"><a href="dates/date.html"><img SRC="../images/code.gif" HSPACE=4 BORDER=0 height=24 width=24 align=TOP></a><a href="dates/date.html">Source</a></td>
</tr>
<tr VALIGN=TOP>
<td>Snoop</td>
<td WIDTH="30%"><a href="snp/snoop.jsp"><img SRC="../images/execute.gif" HSPACE=4 BORDER=0 align=TOP></a><a href="snp/snoop.jsp">Execute</a></td>
<td WIDTH="30%"><a href="snp/snoop.html"><img SRC="../images/code.gif" HSPACE=4 BORDER=0 height=24 width=24 align=TOP></a><a href="snp/snoop.html">Source</a></td>
</tr>
<tr VALIGN=TOP>
<td>ErrorPage </td>
<td WIDTH="30%"><a href="error/error.html"><img SRC="../images/execute.gif" HSPACE=4 BORDER=0 align=TOP></a><a href="error/error.html">Execute</a></td>
<td WIDTH="30%"><a href="error/er.html"><img SRC="../images/code.gif" HSPACE=4 BORDER=0 height=24 width=24 align=TOP></a><a href="error/er.html">Source</a></td>
</tr>
<tr VALIGN=TOP>
<td>Carts </td>
<td VALIGN=TOP WIDTH="30%"><a href="sessions/carts.html"><img SRC="../images/execute.gif" HSPACE=4 BORDER=0 align=TOP></a><a href="sessions/carts.html">Execute</a></td>
<td WIDTH="30%"><a href="sessions/crt.html"><img SRC="../images/code.gif" HSPACE=4 BORDER=0 height=24 width=24 align=TOP></a><a href="sessions/crt.html">Source</a></td>
</tr>
<tr VALIGN=TOP>
<td>Checkbox </td>
<td VALIGN=TOP WIDTH="30%"><a href="/checkbox/check.html"><img SRC="../images/execute.gif" HSPACE=4 BORDER=0 align=TOP></a><a href="checkbox/check.html">Execute</a></td>
<td WIDTH="30%"><a href="colors/cresult.html"><img SRC="../images/code.gif" HSPACE=4 BORDER=0 height=24 width=24 align=TOP></a><a href="checkbox/cresult.html">Source</a></td>
</tr>
<tr VALIGN=TOP>
<td>Color </td>
<td VALIGN=TOP WIDTH="30%"><a href="/colors/colors.html"><img SRC="../images/execute.gif" HSPACE=4 BORDER=0 align=TOP></a><a href="colors/colors.html">Execute</a></td>
<td WIDTH="30%"><a href="colors/clr.html.html"><img SRC="../images/code.gif" HSPACE=4 BORDER=0 height=24 width=24 align=TOP></a><a href="colors/clr.html">Source</a></td>
</tr>
<tr VALIGN=TOP>
<td>Calendar </td>
<td WIDTH="30%"><a href="cal/login.html"><img SRC="../images/execute.gif" HSPACE=4 BORDER=0 align=TOP></a><a href="cal/login.html">Execute</a></td>
<td WIDTH="30%"><a href="cal/calendar.html"><img SRC="../images/code.gif" HSPACE=4 BORDER=0 height=24 width=24 align=TOP></a><a href="cal/calendar.html">Source</a></td>
</tr>
<tr VALIGN=TOP>
<td>Include </td>
<td VALIGN=TOP WIDTH="30%"><a href="/include/include.jsp"><img SRC="../images/execute.gif" HSPACE=4 BORDER=0 align=TOP></a><a href="include/include.jsp">Execute</a></td>
<td WIDTH="30%"><a href="include/inc.html"><img SRC="../images/code.gif" HSPACE=4 BORDER=0 height=24 width=24 align=TOP></a><a href="include/inc.html">Source</a></td>
</tr>
<tr VALIGN=TOP>
<td>Forward </td>
<td VALIGN=TOP WIDTH="30%"><a href="forward/forward.jsp"><img SRC="../images/execute.gif" HSPACE=4 BORDER=0 align=TOP></a><a href="forward/forward.jsp">Execute</a></td>
<td WIDTH="30%"><a href="forward/fwd.html"><img SRC="../images/code.gif" HSPACE=4 BORDER=0 height=24 width=24 align=TOP></a><a href="forward/fwd.html">Source</a></td>
</tr>
<tr VALIGN=TOP>
<td>Plugin </td>
<td VALIGN=TOP WIDTH="30%"><a href="plugin/plugin.jsp"><img SRC="../images/execute.gif" HSPACE=4 BORDER=0 align=TOP></a><a href="plugin/plugin.jsp">Execute</a></td>
<td WIDTH="30%"><a href="plugin/plugin.html"><img SRC="../images/code.gif" HSPACE=4 BORDER=0 height=24 width=24 align=TOP></a><a href="plugin/plugin.html">Source</a></td>
</tr>
<tr VALIGN=TOP>
<td>JSP-Servlet-JSP </td>
<td VALIGN=TOP WIDTH="30%"><a href="jsptoserv/jsptoservlet.jsp"><img SRC="../images/execute.gif" HSPACE=4 BORDER=0 align=TOP></a><a href="jsptoserv/jsptoservlet.jsp">Execute</a></td>
<td WIDTH="30%"><a href="jsptoserv/jts.html"><img SRC="../images/code.gif" HSPACE=4 BORDER=0 height=24 width=24 align=TOP></a><a href="jsptoserv/jts.html">Source</a></td>
</tr>
<tr VALIGN=TOP>
<td>Simple custom tag example</td>
<td VALIGN=TOP WIDTH="30%"><a href="simpletag/foo.jsp"><img SRC="../images/execute.gif" HSPACE=4 BORDER=0 align=TOP></a><a href="simpletag/foo.jsp">Execute</a></td>
<td WIDTH="30%"><a href="simpletag/foo.html"><img SRC="../images/code.gif" HSPACE=4 BORDER=0 height=24 width=24 align=TOP></a><a href="simpletag/foo.html">Source</a></td>
</tr>
</table>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/source.jsp
Index: source.jsp
===================================================================
<%@ taglib uri="http://java.apache.org/tomcat/examples-taglib" prefix="eg" %>
<eg:ShowSource jspFile="<%= request.getQueryString() %>"/>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/cal/Entries.txt
Index: Entries.txt
===================================================================
/*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*/
package cal;
import java.util.Enumeration;
import java.util.Hashtable;
import javax.servlet.http.*;
public class Entries {
private Hashtable entries;
private static final String[] time = {"8am", "9am", "10am", "11am", "12pm",
"1pm", "2pm", "3pm", "4pm", "5pm", "6pm",
"7pm", "8pm" };
public static final int rows = 12;
public Entries () {
entries = new Hashtable (rows);
for (int i=0; i < rows; i++) {
entries.put (time[i], new Entry(time[i]));
}
}
public int getRows () {
return rows;
}
public Entry getEntry (int index) {
return (Entry)this.entries.get(time[index]);
}
public int getIndex (String tm) {
for (int i=0; i<rows; i++)
if(tm.equals(time[i])) return i;
return -1;
}
public void processRequest (HttpServletRequest request, String tm) {
int index = getIndex (tm);
if (index >= 0) {
String descr = request.getParameter ("description");
((Entry)entries.get(time[index])).setDescription (descr);
}
}
}
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/cal/Entry.txt
Index: Entry.txt
===================================================================
/*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*/
package cal;
public class Entry {
String hour;
String description;
String color;
public Entry (String hour) {
this.hour = hour;
this.description = "";
}
public String getHour () {
return this.hour;
}
public String getColor () {
if (description.equals("")) return "lightblue";
else return "red";
}
public String getDescription () {
if (description.equals("")) return "None";
else return this.description;
}
public void setDescription (String descr) {
description = descr;
}
}
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/cal/JspCalendar.txt
Index: JspCalendar.txt
===================================================================
/*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*/
package cal;
import java.text.DateFormat;
import java.util.*;
public class JspCalendar {
Calendar calendar = null;
Date currentDate;
public JspCalendar() {
calendar = Calendar.getInstance();
Date trialTime = new Date();
calendar.setTime(trialTime);
}
public int getYear() {
return calendar.get(Calendar.YEAR);
}
public String getMonth() {
int m = getMonthInt();
String[] months = new String [] { "January", "February", "March",
"April", "May", "June",
"July", "August", "September",
"October", "November", "December" };
if (m > 12)
return "Unknown to Man";
return months[m - 1];
}
public String getDay() {
int x = getDayOfWeek();
String[] days = new String[] {"Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"};
if (x > 7)
return "Unknown to Man";
return days[x - 1];
}
public int getMonthInt() {
return 1 + calendar.get(Calendar.MONTH);
}
public String getDate() {
return getMonthInt() + "/" + getDayOfMonth() + "/" + getYear();
}
public String getCurrentDate() {
Date dt = new Date ();
calendar.setTime (dt);
return getMonthInt() + "/" + getDayOfMonth() + "/" + getYear();
}
public String getNextDate() {
calendar.set (Calendar.DAY_OF_MONTH, getDayOfMonth() + 1);
return getDate ();
}
public String getPrevDate() {
calendar.set (Calendar.DAY_OF_MONTH, getDayOfMonth() - 1);
return getDate ();
}
public String getTime() {
return getHour() + ":" + getMinute() + ":" + getSecond();
}
public int getDayOfMonth() {
return calendar.get(Calendar.DAY_OF_MONTH);
}
public int getDayOfYear() {
return calendar.get(Calendar.DAY_OF_YEAR);
}
public int getWeekOfYear() {
return calendar.get(Calendar.WEEK_OF_YEAR);
}
public int getWeekOfMonth() {
return calendar.get(Calendar.WEEK_OF_MONTH);
}
public int getDayOfWeek() {
return calendar.get(Calendar.DAY_OF_WEEK);
}
public int getHour() {
return calendar.get(Calendar.HOUR_OF_DAY);
}
public int getMinute() {
return calendar.get(Calendar.MINUTE);
}
public int getSecond() {
return calendar.get(Calendar.SECOND);
}
public int getEra() {
return calendar.get(Calendar.ERA);
}
public String getUSTimeZone() {
String[] zones = new String[] {"Hawaii", "Alaskan", "Pacific",
"Mountain", "Central", "Eastern"};
return zones[10 + getZoneOffset()];
}
public int getZoneOffset() {
return calendar.get(Calendar.ZONE_OFFSET)/(60*60*1000);
}
public int getDSTOffset() {
return calendar.get(Calendar.DST_OFFSET)/(60*60*1000);
}
public int getAMPM() {
return calendar.get(Calendar.AM_PM);
}
}
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/cal/TableBean.txt
Index: TableBean.txt
===================================================================
/*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*/
package cal;
import java.beans.*;
import javax.servlet.http.*;
import javax.servlet.*;
import java.util.Hashtable;
public class TableBean {
Hashtable table;
JspCalendar JspCal;
Entries entries;
String date;
String name = null;
String email = null;
boolean processError = false;
public TableBean () {
this.table = new Hashtable (10);
this.JspCal = new JspCalendar ();
this.date = JspCal.getCurrentDate ();
}
public void setName (String nm) {
this.name = nm;
}
public String getName () {
return this.name;
}
public void setEmail (String mail) {
this.email = mail;
}
public String getEmail () {
return this.email;
}
public String getDate () {
return this.date;
}
public Entries getEntries () {
return this.entries;
}
public void processRequest (HttpServletRequest request) {
// Get the name and e-mail.
this.processError = false;
if (name == null) setName(request.getParameter ("name"));
if (email == null) setEmail(request.getParameter ("email"));
if (name == null || email == null) {
this.processError = true;
return;
}
// Get the date.
String dateR = request.getParameter ("date");
if (dateR == null) date = JspCal.getCurrentDate ();
else if (dateR.equalsIgnoreCase("next")) date = JspCal.getNextDate ();
else if (dateR.equalsIgnoreCase("prev")) date = JspCal.getPrevDate ();
entries = (Entries) table.get (date);
if (entries == null) {
entries = new Entries ();
table.put (date, entries);
}
// If time is provided add the event.
String time = request.getParameter("time");
if (time != null) entries.processRequest (request, time);
}
public boolean getProcessError () {
return this.processError;
}
}
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/cal/cal1.jsp
Index: cal1.jsp
===================================================================
<HTML>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<HEAD><TITLE>
Calendar: A JSP APPLICATION
</TITLE></HEAD>
<BODY BGCOLOR="white">
<%@ page language="java" import="cal.*" %>
<jsp:useBean id="table" scope="session" class="cal.TableBean" />
<%
table.processRequest(request);
if (table.getProcessError() == false) {
%>
<!-- html table goes here -->
<CENTER>
<TABLE WIDTH=60% BGCOLOR=yellow CELLPADDING=15>
<TR>
<TD ALIGN=CENTER> <A HREF=cal1.jsp?date=prev> prev </A>
<TD ALIGN=CENTER> Calendar:<%= table.getDate() %></TD>
<TD ALIGN=CENTER> <A HREF=cal1.jsp?date=next> next </A>
</TR>
</TABLE>
<!-- the main table -->
<TABLE WIDTH=60% BGCOLOR=lightblue BORDER=1 CELLPADDING=10>
<TR>
<TH> Time </TH>
<TH> Appointment </TH>
</TR>
<FORM METHOD=POST ACTION=cal1.jsp>
<%
for(int i=0; i<table.getEntries().getRows(); i++) {
cal.Entry entr = table.getEntries().getEntry(i);
%>
<TR>
<TD>
<A HREF=cal2.jsp?time=<%= entr.getHour() %>>
<%= entr.getHour() %> </A>
</TD>
<TD BGCOLOR=<%= entr.getColor() %>>
<%= entr.getDescription() %>
</TD>
</TR>
<%
}
%>
</FORM>
</TABLE>
<BR>
<!-- footer -->
<TABLE WIDTH=60% BGCOLOR=yellow CELLPADDING=15>
<TR>
<TD ALIGN=CENTER> <%= table.getName() %> :
<%= table.getEmail() %> </TD>
</TR>
</TABLE>
</CENTER>
<%
} else {
%>
<font size=5>
You must enter your name and email address correctly.
</font>
<%
}
%>
</BODY>
</HTML>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/cal/cal1.txt
Index: cal1.txt
===================================================================
<HTML>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<HEAD><TITLE>
Calendar: A JSP APPLICATION
</TITLE></HEAD>
<BODY BGCOLOR="white">
<%@ page language="java" import="cal.*" %>
<jsp:useBean id="table" scope="session" class="cal.TableBean" />
<%
table.processRequest(request);
if (table.getProcessError() == false) {
%>
<!-- html table goes here -->
<CENTER>
<TABLE WIDTH=60% BGCOLOR=yellow CELLPADDING=15>
<TR>
<TD ALIGN=CENTER> <A HREF=cal1.jsp?date=prev> prev </A>
<TD ALIGN=CENTER> Calendar:<%= table.getDate() %></TD>
<TD ALIGN=CENTER> <A HREF=cal1.jsp?date=next> next </A>
</TR>
</TABLE>
<!-- the main table -->
<TABLE WIDTH=60% BGCOLOR=lightblue BORDER=1 CELLPADDING=10>
<TR>
<TH> Time </TH>
<TH> Appointment </TH>
</TR>
<FORM METHOD=POST ACTION=cal1.jsp>
<%
for(int i=0; i<table.getEntries().getRows(); i++) {
cal.Entry entr = table.getEntries().getEntry(i);
%>
<TR>
<TD>
<A HREF=cal2.jsp?time=<%= entr.getHour() %>>
<%= entr.getHour() %> </A>
</TD>
<TD BGCOLOR=<%= entr.getColor() %>>
<%= entr.getDescription() %>
</TD>
</TR>
<%
}
%>
</FORM>
</TABLE>
<BR>
<!-- footer -->
<TABLE WIDTH=60% BGCOLOR=yellow CELLPADDING=15>
<TR>
<TD ALIGN=CENTER> <%= table.getName() %> :
<%= table.getEmail() %> </TD>
</TR>
</TABLE>
</CENTER>
<%
} else {
%>
<font size=5>
You must enter your name and email address correctly.
</font>
<%
}
%>
</BODY>
</HTML>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/cal/cal2.jsp
Index: cal2.jsp
===================================================================
<HTML>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<HEAD><TITLE>
Calendar: A JSP APPLICATION
</TITLE></HEAD>
<BODY BGCOLOR="white">
<jsp:useBean id="table" scope="session" class="cal.TableBean" />
<%
String time = request.getParameter ("time");
%>
<FONT SIZE=5> Please add the following event:
<BR> <h3> Date <%= table.getDate() %>
<BR> Time <%= time %> </h3>
</FONT>
<FORM METHOD=POST ACTION=cal1.jsp>
<BR>
<BR> <INPUT NAME="date" TYPE=HIDDEN VALUE="current">
<BR> <INPUT NAME="time" TYPE=HIDDEN VALUE=<%= time %>
<BR> <h2> Description of the event <INPUT NAME="description" TYPE=TEXT SIZE=20> </h2>
<BR> <INPUT TYPE=SUBMIT VALUE="submit">
</FORM>
</BODY>
</HTML>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/cal/cal2.txt
Index: cal2.txt
===================================================================
<HTML>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<HEAD><TITLE>
Calendar: A JSP APPLICATION
</TITLE></HEAD>
<BODY BGCOLOR="white">
<jsp:useBean id="table" scope="session" class="cal.TableBean" />
<%
String time = request.getParameter ("time");
%>
<FONT SIZE=5> Please add the following event:
<BR> <h3> Date <%= table.getDate() %>
<BR> Time <%= time %> </h3>
</FONT>
<FORM METHOD=POST ACTION=cal1.jsp>
<BR>
<BR> <INPUT NAME="date" TYPE=HIDDEN VALUE="current">
<BR> <INPUT NAME="time" TYPE=HIDDEN VALUE=<%= time %>
<BR> <h2> Description of the event <INPUT NAME="description" TYPE=TEXT SIZE=20> </h2>
<BR> <INPUT TYPE=SUBMIT VALUE="submit">
</FORM>
</BODY>
</HTML>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/cal/calendar.html
Index: calendar.html
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<p><font color="#0000FF"><a href="login.html"><img src="../../images/execute.gif" align="right" border="0"></a><a href="../index.html"><img src="../../images/return.gif" width="24" height="24" align="right" border="0"></a></font></p>
<h2> Source Code for Calendar Example. <br>
<h3><a href="cal1.txt">cal1.jsp<font color="#0000FF"></a>
</font> </h3>
<h3><a href="cal2.txt">cal2.jsp<font color="#0000FF"></a>
</font> </h3>
<br>
<h2> Beans.
<h3><a href="TableBean.txt">TableBean<font color="#0000FF"></a>
</font> </h3>
<h3><a href="Entries.txt">Entries<font color="#0000FF"></a>
</font> </h3>
<h3><a href="Entry.txt">Entry<font color="#0000FF"></a>
</font> </h3>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/cal/login.html
Index: login.html
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<head>
<title> Login page for the calendar. </title>
</head>
<body bgcolor="white">
<center>
<font size=7 color="red"> Please Enter the following information: </font>
<br>
<form method=GET action=cal1.jsp>
<font size=5> Name <input type=text name="name" size=20>
</font>
<br>
<font size=5> Email <input type=text name="email" size=20>
</font>
<br>
<input type=submit name=action value="Submit">
</form>
<hr>
<font size=3 color="red"> Note: This application does not implement the complete
functionality of a typical calendar application. It demostartes a way JSP can be
used with html tables and forms.</font>
</center>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/checkbox/CheckTest.html
Index: CheckTest.html
===================================================================
<HTML>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<HEAD>
<title>
checkbox.CheckTest Bean Properties
</title>
<BODY BGCOLOR="white">
<H2>
checkbox.CheckTest Bean Properties
</H2>
<HR>
<DL>
<DT>public class <B>CheckTest</B><DT>extends Object</DL>
<P>
<HR>
<P>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0">
<TR BGCOLOR="#EEEEFF">
<TD COLSPAN=3><FONT SIZE="+2">
<B>Properties Summary</B></FONT></TD>
</TR>
<TR BGCOLOR="white">
<td align="right" valign="top" width="1%">
<FONT SIZE="-1">
String
</FONT></TD>
<TD><B>CheckTest:fruit</B>
<BR>
</TD>
<td width="1%">
<FONT SIZE="-1">
Multi
</FONT></TD>
</TABLE>
<HR>
</BODY>
</HTML>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/checkbox/check.html
Index: check.html
===================================================================
<HTML>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<BODY bgcolor="white">
<FORM TYPE=POST ACTION=checkresult.jsp>
<BR>
<font size=5 color="red">
Check all Favorite fruits: <br>
<input TYPE=checkbox name=fruit VALUE=apples> Apples <BR>
<input TYPE=checkbox name=fruit VALUE=grapes> Grapes <BR>
<input TYPE=checkbox name=fruit VALUE=oranges> Oranges <BR>
<input TYPE=checkbox name=fruit VALUE=melons> Melons <BR>
<br> <INPUT TYPE=submit name=submit Value="Submit">
</font>
</FORM>
</BODY>
</HTML>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/checkbox/checkresult.jsp
Index: checkresult.jsp
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<body bgcolor="white">
<font size=5 color="red">
<%! String[] fruits; %>
<jsp:useBean id="foo" scope="page" class="checkbox.CheckTest" />
<jsp:setProperty name="foo" property="fruit" param="fruit" />
<hr>
The checked fruits (got using request) are: <br>
<%
fruits = request.getParameterValues("fruit");
%>
<ul>
<%
if (fruits != null) {
for (int i = 0; i < fruits.length; i++) {
%>
<li>
<%
out.println (fruits[i]);
}
} else out.println ("none selected");
%>
</ul>
<br>
<hr>
The checked fruits (got using beans) are <br>
<%
fruits = foo.getFruit();
%>
<ul>
<%
if (!fruits[0].equals("1")) {
for (int i = 0; i < fruits.length; i++) {
%>
<li>
<%
out.println (fruits[i]);
}
} else out.println ("none selected");
%>
</ul>
</font>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/checkbox/checkresult.txt
Index: checkresult.txt
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<body bgcolor="white">
<font size=5 color="red">
<%! String[] fruits; %>
<jsp:useBean id="foo" scope="page" class="checkbox.CheckTest" />
<jsp:setProperty name="foo" property="Fruit" param="fruit" />
<hr>
The checked fruits (got using request) are: <br>
<%
fruits = request.getParameterValues("fruit");
%>
<ul>
<%
if (fruits != null) {
for (int i = 0; i < fruits.length; i++) {
%>
<li>
<%
out.println (fruits[i]);
}
} else out.println ("none selected");
%>
</ul>
<br>
<hr>
The checked fruits (got using beans) are <br>
<%
fruits = foo.getFruit();
%>
<ul>
<%
if (!fruits[0].equals("1")) {
for (int i = 0; i < fruits.length; i++) {
%>
<li>
<%
out.println (fruits[i]);
}
} else out.println ("none selected");
%>
</ul>
</font>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/checkbox/cresult.html
Index: cresult.html
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<p><font color="#0000FF"><a href="check.html"><img src="../../images/execute.gif" align="right" border="0"></a><a href="../index.html"><img src="../../images/return.gif" width="24" height="24" align="right" border="0"></a></font></p>
<h3><a href="checkresult.txt">Source Code for Checkbox Example<font color="#0000FF"></a>
</font> </h3>
<h3><a href="CheckTest.html">Property Sheet for CheckTest
<font color="#0000FF"></a> </font> </h3>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/colors/ColorGameBean.html
Index: ColorGameBean.html
===================================================================
<HTML>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<HEAD>
<title>
colors.ColorGameBean Bean Properties
</title>
<BODY BGCOLOR="white">
<H2>
colors.ColorGameBean Bean Properties
</H2>
<HR>
<DL>
<DT>public class <B>ColorGameBean</B><DT>extends Object</DL>
<P>
<HR>
<P>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0">
<TR BGCOLOR="#EEEEFF">
<TD COLSPAN=3><FONT SIZE="+2">
<B>Properties Summary</B></FONT></TD>
</TR>
<TR BGCOLOR="white">
<td align="right" valign="top" width="1%">
<FONT SIZE="-1">
String
</FONT></TD>
<TD><B>ColorGameBean:color2</B>
<BR>
</TD>
<td width="1%">
<FONT SIZE="-1">
Single
</FONT></TD>
<TR BGCOLOR="white">
<td align="right" valign="top" width="1%">
<FONT SIZE="-1">
String
</FONT></TD>
<TD><B>ColorGameBean:color1</B>
<BR>
</TD>
<td width="1%">
<FONT SIZE="-1">
Single
</FONT></TD>
<TR BGCOLOR="white">
<td align="right" valign="top" width="1%">
<FONT SIZE="-1">
int
</FONT></TD>
<TD><B>ColorGameBean:attempts</B>
<BR>
</TD>
<td width="1%">
<FONT SIZE="-1">
Single
</FONT></TD>
<TR BGCOLOR="white">
<td align="right" valign="top" width="1%">
<FONT SIZE="-1">
boolean
</FONT></TD>
<TD><B>ColorGameBean:hint</B>
<BR>
</TD>
<td width="1%">
<FONT SIZE="-1">
Single
</FONT></TD>
<TR BGCOLOR="white">
<td align="right" valign="top" width="1%">
<FONT SIZE="-1">
boolean
</FONT></TD>
<TD><B>ColorGameBean:success</B>
<BR>
</TD>
<td width="1%">
<FONT SIZE="-1">
Single
</FONT></TD>
<TR BGCOLOR="white">
<td align="right" valign="top" width="1%">
<FONT SIZE="-1">
boolean
</FONT></TD>
<TD><B>ColorGameBean:hintTaken</B>
<BR>
</TD>
<td width="1%">
<FONT SIZE="-1">
Single
</FONT></TD>
</TABLE>
<HR>
</BODY>
</HTML>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/colors/clr.html
Index: clr.html
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<p><font color="#0000FF"><a href="colors.html"><img src="../../images/execute.gif" align="right" border="0"></a><a href="../index.html"><img src="../../images/return.gif" width="24" height="24" align="right" border="0"></a></font></p>
<h3><a href="colors.txt">Source Code for Color Example<font color="#0000FF"></a>
</font> </h3>
<h3><a href="ColorGameBean.html">Property Sheet for ColorGameBean
<font color="#0000FF"></a> </font> </h3>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/colors/colors.html
Index: colors.html
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<body bgcolor= white>
<font size=6 color=red>
<hr>
This web page is an example using JSP and BEANs.
<p>
Guess my favorite two colors
<p> If you fail to guess both of them - you get yellow on red.
<p> If you guess one of them right, either your foreground or
your background will change to the color that was guessed right.
<p> Guess them both right and your browser foreground/background
will change to my two favorite colors to display this page.
<hr>
<form method=GET action=colrs.jsp>
Color #1: <input type=text name= color1 size=16>
<br>
Color #2: <input type=text name= color2 size=16>
<p>
<input type=submit name=action value="Submit">
<input type=submit name=action value="Hint">
</form>
</font>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/colors/colors.txt
Index: colors.txt
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<jsp:useBean id="cb" scope="session" class="colors.ColorGameBean" />
<jsp:setProperty name="cb" property="*" />
<%
cb.processRequest(request);
%>
<body bgcolor=<%= cb.getColor1() %>>
<font size=6 color=<%= cb.getColor2() %>>
<p>
<% if (cb.getHint()==true) { %>
<p> Hint #1: Vampires prey at night!
<p> <p> Hint #2: Nancy without the n.
<% } %>
<% if (cb.getSuccess()==true) { %>
<p> CONGRATULATIONS!!
<% if (cb.getHintTaken()==true) { %>
<p> ( although I know you cheated and peeked into the hints)
<% } %>
<% } %>
<p> Total attempts so far: <%= cb.getAttempts() %>
<p>
<p>
<form method=POST action=colrs.jsp>
Color #1: <input type=text name= color1 size=16>
<br>
Color #2: <input type=text name= color2 size=16>
<p>
<input type=submit name=action value="Submit">
<input type=submit name=action value="Hint">
</form>
</font>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/colors/colrs.jsp
Index: colrs.jsp
===================================================================
<html>
<!--
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
-->
<jsp:useBean id="cb" scope="session" class="colors.ColorGameBean" />
<jsp:setProperty name="cb" property="*" />
<%
cb.processRequest(request);
%>
<body bgcolor=<%= cb.getColor1() %>>
<font size=6 color=<%= cb.getColor2() %>>
<p>
<% if (cb.getHint()==true) { %>
<p> Hint #1: Vampires prey at night!
<p> <p> Hint #2: Nancy without the n.
<% } %>
<% if (cb.getSuccess()==true) { %>
<p> CONGRATULATIONS!!
<% if (cb.getHintTaken()==true) { %>
<p> ( although I know you cheated and peeked into the hints)
<% } %>
<% } %>
<p> Total attempts so far: <%= cb.getAttempts() %>
<p>
<p>
<form method=POST action=colrs.jsp>
Color #1: <input type=text name= color1 size=16>
<br>
Color #2: <input type=text name= color2 size=16>
<p>
<input type=submit name=action value="Submit">
<input type=submit name=action value="Hint">
</form>
</font>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/dates/date.html
Index: date.html
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<p><font color="#0000FF"><a href="date.jsp"><img src="../../images/execute.gif" align="right" border="0"></a><a href="../index.html"><img src="../../images/return.gif" width="24" height="24" align="right" border="0"></a></font></p>
<h3><a href="date.txt">Source Code for Date Example<font color="#0000FF"></a>
</font> </h3>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/dates/date.jsp
Index: date.jsp
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<%@ page session="false"%>
<body bgcolor="white">
<jsp:useBean id='clock' scope='page' class='dates.JspCalendar' type="dates.JspCalendar" />
<font size=4>
<ul>
<li> Day of month: is <jsp:getProperty name="clock" property="dayOfMonth"/>
<li> Year: is <jsp:getProperty name="clock" property="year"/>
<li> Month: is <jsp:getProperty name="clock" property="month"/>
<li> Time: is <jsp:getProperty name="clock" property="time"/>
<li> Date: is <jsp:getProperty name="clock" property="date"/>
<li> Day: is <jsp:getProperty name="clock" property="day"/>
<li> Day Of Year: is <jsp:getProperty name="clock" property="dayOfYear"/>
<li> Week Of Year: is <jsp:getProperty name="clock" property="weekOfYear"/>
<li> era: is <jsp:getProperty name="clock" property="era"/>
<li> DST Offset: is <jsp:getProperty name="clock" property="DSTOffset"/>
<li> Zone Offset: is <jsp:getProperty name="clock" property="zoneOffset"/>
</ul>
</font>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/dates/date.txt
Index: date.txt
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<body bgcolor="white">
<jsp:useBean id='clock' scope='page' class='dates.JspCalendar' type="dates.JspCalendar" />
<font size=4>
<ul>
<li> Day of month: is <jsp:getProperty name="clock" property="dayOfMonth"/>
<li> Year: is <jsp:getProperty name="clock" property="year"/>
<li> Month: is <jsp:getProperty name="clock" property="month"/>
<li> Time: is <jsp:getProperty name="clock" property="time"/>
<li> Date: is <jsp:getProperty name="clock" property="date"/>
<li> Day: is <jsp:getProperty name="clock" property="day"/>
<li> Day Of Year: is <jsp:getProperty name="clock" property="dayOfYear"/>
<li> Week Of Year: is <jsp:getProperty name="clock" property="weekOfYear"/>
<li> era: is <jsp:getProperty name="clock" property="era"/>
<li> DST Offset: is <jsp:getProperty name="clock" property="DSTOffset"/>
<li> Zone Offset: is <jsp:getProperty name="clock" property="zoneOffset"/>
</ul>
</font>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/error/er.html
Index: er.html
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<p><font color="#0000FF"><a href="error.html"><img src="../../images/execute.gif" align="right" border="0"></a><a href="../index.html"><img src="../../images/return.gif" width="24" height="24" align="right" border="0"></a></font></p>
<h3><a href="err.txt">Source Code for Error Example<font color="#0000FF"></a>
</font> </h3>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/error/err.jsp
Index: err.jsp
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<body bgcolor="lightblue">
<%@ page errorPage="errorpge.jsp" %>
<jsp:useBean id="foo" scope="request" class="error.Smart" />
<%
String name = null;
if (request.getParameter("name") == null) {
%>
<%@ include file="/jsp/error/error.html" %>
<%
} else {
foo.setName(request.getParameter("name"));
if (foo.getName().equalsIgnoreCase("integra"))
name = "acura";
if (name.equalsIgnoreCase("acura")) {
%>
<H1> Yes!!! <a href="http://www.acura.com">Acura</a> is my favorite car.
<%
}
}
%>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/error/err.txt
Index: err.txt
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<body bgcolor="lightblue">
<%@ page errorPage="errorpge.jsp" %>
<jsp:useBean id="foo" scope="request" class="error.Smart" />
<%
String name = null;
if (request.getParameter("name") == null) {
%>
<%@ include file="/jsp/error/error.html" %>
<%
} else {
foo.setName(request.getParameter("name"));
if (foo.getName().equalsIgnoreCase("integra"))
name = "acura";
if (name.equalsIgnoreCase("acura")) {
%>
<H1> Yes!!! <a href="http://www.acura.com">Acura</a> is my favorite car.
<%
}
}
%>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/error/error.html
Index: error.html
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<body bgcolor="white">
<h1> This example uses <b>errorpage</b> directive </h1>
<br>
<h3> Select my favourite car.</h3>
<form method=get action=err.jsp>
<!-- <br> Make a guess: -->
<SELECT NAME="name" SIZE=5>
<OPTION VALUE="integra"> Acura Integra <BR>
<OPTION VALUE="bmw328i"> BMW 328I <BR>
<OPTION VALUE="z3"> BMW Z3 <BR>
<OPTION VALUE="infiniti"> InfinitiQ3 <BR>
<OPTION VALUE="audi"> Audi A8 <BR>
</SELECT>
<br> <INPUT TYPE=submit name=submit Value="Submit">
</form>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/error/errorpge.jsp
Index: errorpge.jsp
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<body bgcolor="red">
<%@ page isErrorPage="true" %>
<h1> The exception <%= exception.getMessage() %> tells me you
made a wrong choice.
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/forward/er.html
Index: er.html
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<p><font color="#0000FF"><a href="error.html"><img src="../../images/execute.gif" align="right" border="0"></a><a href="../index.html"><img src="../../images/return.gif" width="24" height="24" align="right" border="0"></a></font></p>
<h3><a href="err.txt">Source Code for Error Example<font color="#0000FF"></a>
</font> </h3>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/forward/err.jsp
Index: err.jsp
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<body bgcolor="lightblue">
<%@ page errorPage="errorpge.jsp" %>
<jsp:useBean id="foo" scope="request" class="error.Smart" />
<%
String name = null;
if (request.getParameter("name") == null) {
%>
<%@ include file="/jsp/error/error.html" %>
<%
} else {
foo.setName(request.getParameter("name"));
if (foo.getName().equalsIgnoreCase("integra"))
name = "acura";
if (name.equalsIgnoreCase("acura")) {
%>
<H1> Yes!!! <a href="http://www.acura.com">Acura</a> is my favorite car.
<%
}
}
%>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/forward/err.txt
Index: err.txt
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<body bgcolor="lightblue">
<%@ page errorPage="errorpge.jsp" %>
<jsp:useBean id="foo" scope="request" class="error.Smart" />
<%
String name = null;
if (request.getParameter("name") == null) {
%>
<%@ include file="/jsp/error/error.html" %>
<%
} else {
foo.setName(request.getParameter("name"));
if (foo.getName().equalsIgnoreCase("integra"))
name = "acura";
if (name.equalsIgnoreCase("acura")) {
%>
<H1> Yes!!! <a href="http://www.acura.com">Acura</a> is my favorite car.
<%
}
}
%>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/forward/error.html
Index: error.html
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<body bgcolor="white">
<h1> This example uses <b>errorpage</b> directive </h1>
<br>
<h3> Select my favourite car.</h3>
<form method=get action=err.jsp>
<!-- <br> Make a guess: -->
<SELECT NAME="name" SIZE=5>
<OPTION VALUE="integra"> Acura Integra <BR>
<OPTION VALUE="bmw328i"> BMW 328I <BR>
<OPTION VALUE="z3"> BMW Z3 <BR>
<OPTION VALUE="infiniti"> InfinitiQ3 <BR>
<OPTION VALUE="audi"> Audi A8 <BR>
</SELECT>
<br> <INPUT TYPE=submit name=submit Value="Submit">
</form>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/forward/errorpge.jsp
Index: errorpge.jsp
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<body bgcolor="red">
<%@ page isErrorPage="true" %>
<h1> The exception <%= exception.getMessage() %> tells me you
made a wrong choice.
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/include/foo.html
Index: foo.html
===================================================================
To get the current time in ms
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/include/foo.jsp
Index: foo.jsp
===================================================================
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<body bgcolor="white">
<font color="red">
<%= System.currentTimeMillis() %>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/include/inc.html
Index: inc.html
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<p><font color="#0000FF"><a href="include.jsp"><img src="../../images/execute.gif" align="right" border="0"></a><a href="../index.html"><img src="../../images/return.gif" width="24" height="24" align="right" border="0"></a></font></p>
<h3><a href="include.txt">Source Code for Include Example<font color="#0000FF"></a>
</font> </h3>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/include/include.jsp
Index: include.jsp
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<body bgcolor="white">
<font color="red">
<%@ page buffer="5" autoFlush="false" %>
<p>In place evaluation of another JSP which gives you the current time:
<%@ include file="foo.jsp" %>
<p> <jsp:include page="/jsp/include/foo.html" flush="true"/> by including the output of another JSP:
<jsp:include page="foo.jsp" flush="true"/>
:-)
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/include/include.txt
Index: include.txt
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<body bgcolor="white">
<font color="red">
<%@ page buffer="5" autoFlush="false" %>
<p>In place evaluation of another JSP which gives you the current time:
<%@ include file="foo.jsp" %>
<p> <jsp:include page="/jsp/include/foo.html" flush="true"/> by including the output of another JSP:
<jsp:include page="foo.jsp" flush="true"/>
:-)
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/jsptoserv/hello.jsp
Index: hello.jsp
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<body bgcolor="white">
<h1>
I have been invoked by
<% out.print (request.getAttribute("servletName").toString()); %>
Servlet.
</h1>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/jsptoserv/jsptoservlet.jsp
Index: jsptoservlet.jsp
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<body bgcolor="white">
<!-- Forward to a servlet -->
<jsp:forward page="/servlet/servletToJsp" />
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/jsptoserv/jts.html
Index: jts.html
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<p><font color="#0000FF"><a href="jsptoservlet.jsp"><img src="../../images/execute.gif" align="right" border="0"></a><a href="../index.html"><img src="../../images/return.gif" width="24" height="24" align="right" border="0"></a></font></p>
<h3><a href="jts.txt">Source Code for JSP calling servlet <font color="#0000FF"></a>
</font> </h3>
<h3><a href="stj.txt">Source Code for Servlet calling JSP
<font color="#0000FF"></a> </font> </h3>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/jsptoserv/jts.txt
Index: jts.txt
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<body bgcolor="white">
<!-- Forward to a servlet -->
<jsp:forward page="/servlet/servletToJsp" />
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/jsptoserv/stj.txt
Index: stj.txt
===================================================================
/**
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*/
import javax.servlet.*;
import javax.servlet.http.*;
public class servletToJsp extends HttpServlet {
public void doGet (HttpServletRequest request,
HttpServletResponse response) {
try {
// Set the attribute and Forward to hello.jsp
request.setAttribute ("servletName", "servletToJsp");
getServletConfig().getServletContext().getRequestDispatcher("/jsp/jsptoserv/hello.jsp").forward(request, response);
} catch (Exception ex) {
ex.printStackTrace ();
}
}
}
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/num/numguess.html
Index: numguess.html
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
Number Guess Game
Written by Jason Hunter, CTO, K&A Software
http://www.servlets.com
-->
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<p><font color="#0000FF"><a href="numguess.jsp"><img src="../../images/execute.gif" align="right" border="0"></a><a href="../index.html"><img src="../../images/return.gif" width="24" height="24" align="right" border="0"></a></font></p>
<h3><a href="/examples/jsp/source.jsp?/jsp/num/numguess.jsp">Source Code for Numguess Example<font color="#0000FF"></a>
</font> </h3>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/num/numguess.jsp
Index: numguess.jsp
===================================================================
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
Number Guess Game
Written by Jason Hunter, CTO, K&A Software
http://www.servlets.com
-->
<%@ page import = "num.NumberGuessBean" %>
<jsp:useBean id="numguess" class="num.NumberGuessBean" scope="session"/>
<jsp:setProperty name="numguess" property="*"/>
<html>
<head><title>Number Guess</title></head>
<body bgcolor="white">
<font size=4>
<% if (numguess.getSuccess()) { %>
Congratulations! You got it.
And after just <%= numguess.getNumGuesses() %> tries.<p>
<% numguess.reset(); %>
Care to <a href="numguess.jsp">try again</a>?
<% } else if (numguess.getNumGuesses() == 0) { %>
Welcome to the Number Guess game.<p>
I'm thinking of a number between 1 and 100.<p>
<form method=get>
What's your guess? <input type=text name=guess>
<input type=submit value="Submit">
</form>
<% } else { %>
Good guess, but nope. Try <b><%= numguess.getHint() %></b>.
You have made <%= numguess.getNumGuesses() %> guesses.<p>
I'm thinking of a number between 1 and 100.<p>
<form method=get>
What's your guess? <input type=text name=guess>
<input type=submit value="Submit">
</form>
<% } %>
</font>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/num/numguess.txt
Index: numguess.txt
===================================================================
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
Number Guess Game
Written by Jason Hunter, CTO, K&A Software
http://www.servlets.com
-->
<%@ page import = "num.NumberGuessBean" %>
<jsp:useBean id="numguess" class="num.NumberGuessBean" scope="session"/>
<jsp:setProperty name="numguess" property="*"/>
<html>
<head><title>Number Guess</title></head>
<body bgcolor="white">
<font size=4>
<% if (numguess.getSuccess()) { %>
Congratulations! You got it.
And after just <%= numguess.getNumGuesses() %> tries.<p>
<% numguess.reset(); %>
Care to <a href="numguess.jsp">try again</a>?
<% } else if (numguess.getNumGuesses() == 0) { %>
Welcome to the Number Guess game.<p>
I'm thinking of a number between 1 and 100.<p>
<form method=get>
What's your guess? <input type=text name=guess>
<input type=submit value="Submit">
</form>
<% } else { %>
Good guess, but nope. Try <b><%= numguess.getHint() %></b>.
You have made <%= numguess.getNumGuesses() %> guesses.<p>
I'm thinking of a number between 1 and 100.<p>
<form method=get>
What's your guess? <input type=text name=guess>
<input type=submit value="Submit">
</form>
<% } %>
</font>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/plugin/plugin.html
Index: plugin.html
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<p><font color="#0000FF"><a href="plugin.jsp"><img src="../../images/execute.gif" align="right" border="0"></a><a href="../index.html"><img src="../../images/return.gif" width="24" height="24" align="right" border="0"></a></font></p>
<h3><a href="plugin.txt">Source Code for Plugin Example<font color="#0000FF"></a>
</font> </h3>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/plugin/plugin.jsp
Index: plugin.jsp
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<title> Plugin example </title>
<body bgcolor="white">
<h3> Current time is : </h3>
<jsp:plugin type="applet" code="Clock2.class" codebase="/examples/jsp/plugin/applet" jreversion="1.2" width="160" height="150" >
<jsp:fallback>
Plugin tag OBJECT or EMBED not supported by browser.
</jsp:fallback>
</jsp:plugin>
<p>
<h4>
<font color=red>
The above applet is loaded using the Java Plugin from a jsp page using the
plugin tag.
</font>
</h4>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/plugin/plugin.txt
Index: plugin.txt
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<title> Plugin example </title>
<body bgcolor="white">
<h3> Current time is : </h3>
<jsp:plugin type="applet" code="Clock2.class" codebase="/examples/jsp/plgin/applet" jreversion="1.2" width="160" height="150" >
<jsp:fallback>
Plugin tag OBJECT or EMBED not supported by browser.
</jsp:fallback>
</jsp:plugin>
<p>
<h4>
<font color=red>
The above applet is loaded using the Java Plugin from a jsp page using the
plugin tag.
</font>
</h4>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/plugin/applet/Clock2.java
Index: Clock2.java
===================================================================
/*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*/
import java.util.*;
import java.awt.*;
import java.applet.*;
import java.text.*;
/**
* Time!
*
* @author Rachel Gollub
*/
public class Clock2 extends Applet implements Runnable {
Thread timer; // The thread that displays clock
int lastxs, lastys, lastxm,
lastym, lastxh, lastyh; // Dimensions used to draw hands
SimpleDateFormat formatter; // Formats the date displayed
String lastdate; // String to hold date displayed
Font clockFaceFont; // Font for number display on clock
Date currentDate; // Used to get date to display
Color handColor; // Color of main hands and dial
Color numberColor; // Color of second hand and numbers
public void init() {
int x,y;
lastxs = lastys = lastxm = lastym = lastxh = lastyh = 0;
formatter = new SimpleDateFormat ("EEE MMM dd hh:mm:ss yyyy", Locale.getDefault());
currentDate = new Date();
lastdate = formatter.format(currentDate);
clockFaceFont = new Font("Serif", Font.PLAIN, 14);
handColor = Color.blue;
numberColor = Color.darkGray;
try {
setBackground(new Color(Integer.parseInt(getParameter("bgcolor"),16)));
} catch (Exception E) { }
try {
handColor = new Color(Integer.parseInt(getParameter("fgcolor1"),16));
} catch (Exception E) { }
try {
numberColor = new Color(Integer.parseInt(getParameter("fgcolor2"),16));
} catch (Exception E) { }
resize(300,300); // Set clock window size
}
// Plotpoints allows calculation to only cover 45 degrees of the circle,
// and then mirror
public void plotpoints(int x0, int y0, int x, int y, Graphics g) {
g.drawLine(x0+x,y0+y,x0+x,y0+y);
g.drawLine(x0+y,y0+x,x0+y,y0+x);
g.drawLine(x0+y,y0-x,x0+y,y0-x);
g.drawLine(x0+x,y0-y,x0+x,y0-y);
g.drawLine(x0-x,y0-y,x0-x,y0-y);
g.drawLine(x0-y,y0-x,x0-y,y0-x);
g.drawLine(x0-y,y0+x,x0-y,y0+x);
g.drawLine(x0-x,y0+y,x0-x,y0+y);
}
// Circle is just Bresenham's algorithm for a scan converted circle
public void circle(int x0, int y0, int r, Graphics g) {
int x,y;
float d;
x=0;
y=r;
d=5/4-r;
plotpoints(x0,y0,x,y,g);
while (y>x){
if (d<0) {
d=d+2*x+3;
x++;
}
else {
d=d+2*(x-y)+5;
x++;
y--;
}
plotpoints(x0,y0,x,y,g);
}
}
// Paint is the main part of the program
public void paint(Graphics g) {
int xh, yh, xm, ym, xs, ys, s = 0, m = 10, h = 10, xcenter, ycenter;
String today;
currentDate = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("s",Locale.getDefault());
try {
s = Integer.parseInt(formatter.format(currentDate));
} catch (NumberFormatException n) {
s = 0;
}
formatter.applyPattern("m");
try {
m = Integer.parseInt(formatter.format(currentDate));
} catch (NumberFormatException n) {
m = 10;
}
formatter.applyPattern("h");
try {
h = Integer.parseInt(formatter.format(currentDate));
} catch (NumberFormatException n) {
h = 10;
}
formatter.applyPattern("EEE MMM dd HH:mm:ss yyyy");
today = formatter.format(currentDate);
xcenter=80;
ycenter=55;
// a= s* pi/2 - pi/2 (to switch 0,0 from 3:00 to 12:00)
// x = r(cos a) + xcenter, y = r(sin a) + ycenter
xs = (int)(Math.cos(s * 3.14f/30 - 3.14f/2) * 45 + xcenter);
ys = (int)(Math.sin(s * 3.14f/30 - 3.14f/2) * 45 + ycenter);
xm = (int)(Math.cos(m * 3.14f/30 - 3.14f/2) * 40 + xcenter);
ym = (int)(Math.sin(m * 3.14f/30 - 3.14f/2) * 40 + ycenter);
xh = (int)(Math.cos((h*30 + m/2) * 3.14f/180 - 3.14f/2) * 30 + xcenter);
yh = (int)(Math.sin((h*30 + m/2) * 3.14f/180 - 3.14f/2) * 30 + ycenter);
// Draw the circle and numbers
g.setFont(clockFaceFont);
g.setColor(handColor);
circle(xcenter,ycenter,50,g);
g.setColor(numberColor);
g.drawString("9",xcenter-45,ycenter+3);
g.drawString("3",xcenter+40,ycenter+3);
g.drawString("12",xcenter-5,ycenter-37);
g.drawString("6",xcenter-3,ycenter+45);
// Erase if necessary, and redraw
g.setColor(getBackground());
if (xs != lastxs || ys != lastys) {
g.drawLine(xcenter, ycenter, lastxs, lastys);
g.drawString(lastdate, 5, 125);
}
if (xm != lastxm || ym != lastym) {
g.drawLine(xcenter, ycenter-1, lastxm, lastym);
g.drawLine(xcenter-1, ycenter, lastxm, lastym); }
if (xh != lastxh || yh != lastyh) {
g.drawLine(xcenter, ycenter-1, lastxh, lastyh);
g.drawLine(xcenter-1, ycenter, lastxh, lastyh); }
g.setColor(numberColor);
g.drawString("", 5, 125);
g.drawString(today, 5, 125);
g.drawLine(xcenter, ycenter, xs, ys);
g.setColor(handColor);
g.drawLine(xcenter, ycenter-1, xm, ym);
g.drawLine(xcenter-1, ycenter, xm, ym);
g.drawLine(xcenter, ycenter-1, xh, yh);
g.drawLine(xcenter-1, ycenter, xh, yh);
lastxs=xs; lastys=ys;
lastxm=xm; lastym=ym;
lastxh=xh; lastyh=yh;
lastdate = today;
currentDate=null;
}
public void start() {
timer = new Thread(this);
timer.start();
}
public void stop() {
timer = null;
}
public void run() {
Thread me = Thread.currentThread();
while (timer == me) {
try {
Thread.currentThread().sleep(100);
} catch (InterruptedException e) {
}
repaint();
}
}
public void update(Graphics g) {
paint(g);
}
public String getAppletInfo() {
return "Title: A Clock \nAuthor: Rachel Gollub, 1995 \nAn analog clock.";
}
public String[][] getParameterInfo() {
String[][] info = {
{"bgcolor", "hexadecimal RGB number", "The background color. Default is the color of your browser."},
{"fgcolor1", "hexadecimal RGB number", "The color of the hands and dial. Default is blue."},
{"fgcolor2", "hexadecimal RGB number", "The color of the seconds hand and numbers. Default is dark gray."}
};
return info;
}
}
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/security/login/error.jsp
Index: error.jsp
===================================================================
<html>
<head>
<title>Login Error</title>
</head>
<body bgcolor=white>
Login error -- please try <a href="login.jsp">again</a>.
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/security/login/login.jsp
Index: login.jsp
===================================================================
<html>
<body>
<h1>Login page for examples</h1>
<form method="POST" action="j_security_check" >
<input type="text" name="j_username">
<input type="password" name="j_password">
<input type="submit" name="j_security_check">
</form>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/security/protected/index.jsp
Index: index.jsp
===================================================================
<html>
<head>
<title>Protected Area Page</title>
</head>
<body bgcolor="white">
You are logged in as remote user <b><%= request.getRemoteUser() %></b><br><br>
<%
if (request.getUserPrincipal() != null) {
%>
Your user principal name is <b><%= request.getUserPrincipal().getName() %></b><br><br>
<%
} else {
%>
No user principal could be identified.
<%
}
%>
<%
String role = request.getParameter("role");
if (role == null)
role = "";
if (role.length() > 0) {
if (request.isUserInRole(role)) {
%>
You have been granted role <b><%= role %></b><br><br>
<%
} else {
%>
You have <i>not</i> been granted role <b><%= role %></b><br><br>
<%
}
}
%>
To check whether your username has been granted a particular role,
enter it here:
<form method="GET">
<input type="text" name="role" value="<%= role %>">
</form>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/sessions/DummyCart.html
Index: DummyCart.html
===================================================================
<HTML>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<HEAD>
<title>
sessions.DummyCart Bean Properties
</title>
<BODY BGCOLOR="white">
<H2>
sessions.DummyCart Bean Properties
</H2>
<HR>
<DL>
<DT>public class <B>DummyCart</B><DT>extends Object</DL>
<P>
<HR>
<P>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0">
<TR BGCOLOR="#EEEEFF">
<TD COLSPAN=3><FONT SIZE="+2">
<B>Properties Summary</B></FONT></TD>
</TR>
<TR BGCOLOR="white">
<td align="right" valign="top" width="1%">
<FONT SIZE="-1">
String
</FONT></TD>
<TD><B>DummyCart:items</B>
<BR>
</TD>
<td width="1%">
<FONT SIZE="-1">
Multi
</FONT></TD>
</TABLE>
<HR>
</BODY>
</HTML>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/sessions/carts.html
Index: carts.html
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<head>
<title>carts</title>
</head>
<body bgcolor="white">
<font size = 5 color="#CC0000">
<form type=POST action=carts.jsp>
<BR>
Please enter item to add or remove:
<br>
Add Item:
<SELECT NAME="item">
<OPTION>Beavis & Butt-head Video collection
<OPTION>X-files movie
<OPTION>Twin peaks tapes
<OPTION>NIN CD
<OPTION>JSP Book
<OPTION>Concert tickets
<OPTION>Love life
<OPTION>Switch blade
<OPTION>Rex, Rugs & Rock n' Roll
</SELECT>
<br> <br>
<INPUT TYPE=submit name="submit" value="add">
<INPUT TYPE=submit name="submit" value="remove">
</form>
</FONT>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/sessions/carts.jsp
Index: carts.jsp
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<jsp:useBean id="cart" scope="session" class="sessions.DummyCart" />
<jsp:setProperty name="cart" property="*" />
<%
cart.processRequest(request);
%>
<FONT size = 5 COLOR="#CC0000">
<br> You have the following items in your cart:
<ol>
<%
String[] items = cart.getItems();
for (int i=0; i<items.length; i++) {
%>
<li> <%= items[i] %>
<%
}
%>
</ol>
</FONT>
<hr>
<%@ include file ="/jsp/sessions/carts.html" %>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/sessions/carts.txt
Index: carts.txt
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<jsp:useBean id="cart" scope="session" class="sessions.DummyCart" />
<jsp:setProperty name="cart" property="*" />
<%
cart.processRequest(request);
%>
<FONT size = 5 COLOR="#CC0000">
<br> You have the following items in your cart:
<ol>
<%
String[] items = cart.getItems();
for (int i=0; i<items.length; i++) {
%>
<li> <%= items[i] %>
<%
}
%>
</ol>
</FONT>
<hr>
<%@ include file ="/jsp/sessions/carts.html" %>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/sessions/crt.html
Index: crt.html
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<p><font color="#0000FF"><a href="carts.html"><img src="../../images/execute.gif" align="right" border="0"></a><a href="../index.html"><img src="../../images/return.gif" width="24" height="24" align="right" border="0"></a></font></p>
<h3><a href="carts.txt">Source Code for Cart Example<font color="#0000FF"></a>
</font> </h3>
<h3><a href="DummyCart.html">Property Sheet for DummyCart
<font color="#0000FF"></a> </font> </h3>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/simpletag/foo.html
Index: foo.html
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<p><font color="#0000FF"><a href="foo.jsp"><img src="../../images/execute.gif" align="right" border="0"></a><a href="../index.html"><img src="../../images/return.gif" width="24" height="24" align="right" border="0"></a></font></p>
<h3><a href="foo.txt">Source Code for the Simple Tag Example<font color="#0000FF"></a>
</font> </h3>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/simpletag/foo.jsp
Index: foo.jsp
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<body>
<%@ taglib uri="http://java.apache.org/tomcat/examples-taglib" prefix="eg" %>
Radio stations that rock:
<ul>
<eg:foo att1="98.5" att2="92.3" att3="107.7">
<li><%= member %></li>
</eg:foo>
</ul>
<eg:log>
Did you see me on the stderr window?
</eg:log>
<eg:log toBrowser="true">
Did you see me on the browser window as well?
</eg:log>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/simpletag/foo.txt
Index: foo.txt
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<body>
<%@ taglib uri="http://java.apache.org/tomcat/examples-taglib" prefix="eg" %>
Radio stations that rock:
<ul>
<eg:foo att1="98.5" att2="92.3" att3="107.7">
<li><%= member %></li>
</eg:foo>
</ul>
<eg:log>
Did you see me on the stderr window?
</eg:log>
<eg:log toBrowser="true">
Did you see me on the browser window as well?
</eg:log>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/snp/snoop.html
Index: snoop.html
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<p><font color="#0000FF"><a href="snoop.jsp"><img src="../../images/execute.gif" align="right" border="0"></a><a href="../index.html"><img src="../../images/return.gif" width="24" height="24" align="right" border="0"></a></font></p>
<h3><a href="snoop.txt">Source Code for Request Parameters Example<font color="#0000FF"></a>
</font> </h3>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/snp/snoop.jsp
Index: snoop.jsp
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<body bgcolor="white">
<h1> Request Information </h1>
<font size="4">
JSP Request Method: <%= request.getMethod() %>
<br>
Request URI: <%= request.getRequestURI() %>
<br>
Request Protocol: <%= request.getProtocol() %>
<br>
Servlet path: <%= request.getServletPath() %>
<br>
Path info: <%= request.getPathInfo() %>
<br>
Path translated: <%= request.getPathTranslated() %>
<br>
Query string: <%= request.getQueryString() %>
<br>
Content length: <%= request.getContentLength() %>
<br>
Content type: <%= request.getContentType() %>
<br>
Server name: <%= request.getServerName() %>
<br>
Server port: <%= request.getServerPort() %>
<br>
Remote user: <%= request.getRemoteUser() %>
<br>
Remote address: <%= request.getRemoteAddr() %>
<br>
Remote host: <%= request.getRemoteHost() %>
<br>
Authorization scheme: <%= request.getAuthType() %>
<br>
Locale: <%= request.getLocale() %>
<hr>
The browser you are using is <%= request.getHeader("User-Agent") %>
<hr>
</font>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/jsp/snp/snoop.txt
Index: snoop.txt
===================================================================
<html>
<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
-->
<body bgcolor="white">
<h1> Request Information </h1>
<font size="4">
JSP Request Method: <%= request.getMethod() %>
<br>
Request URI: <%= request.getRequestURI() %>
<br>
Request Protocol: <%= request.getProtocol() %>
<br>
Servlet path: <%= request.getServletPath() %>
<br>
Path info: <%= request.getPathInfo() %>
<br>
Path translated: <%= request.getPathTranslated() %>
<br>
Query string: <%= request.getQueryString() %>
<br>
Content length: <%= request.getContentLength() %>
<br>
Content type: <%= request.getContentType() %>
<br>
Server name: <%= request.getServerName() %>
<br>
Server port: <%= request.getServerPort() %>
<br>
Remote user: <%= request.getRemoteUser() %>
<br>
Remote address: <%= request.getRemoteAddr() %>
<br>
Remote host: <%= request.getRemoteHost() %>
<br>
Authorization scheme: <%= request.getAuthType() %>
<hr>
The browser you are using is <%= request.getHeader("User-Agent") %>
<hr>
</font>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/servlets/cookies.html
Index: cookies.html
===================================================================
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<p><font color="#0000FF"><a href="../servlet/CookieExample"><img src="../images/execute.gif" align="right" border="0"></a><a href="index.html"><img src="../images/return.gif" width="24" height="24" align="right" border="0"></a></font></p>
<h3>Source Code for Cookie Example<font color="#0000FF"><br>
</font> </h3>
<font color="#0000FF"></font>
<pre><font color="#0000FF">import</font> java.io.*;
<font color="#0000FF">import</font> javax.servlet.*;
<font color="#0000FF">import</font> javax.servlet.http.*;
<font color="#0000FF">public class</font> CookieExample <font color="#0000FF">extends</font> HttpServlet {
<font color="#0000FF">public void</font> doGet(HttpServletRequest request, HttpServletResponse response)
<font color="#0000FF">throws</font> IOException, ServletException
{
response.setContentType("<font color="#009900">text/html</font>");
PrintWriter out = response.getWriter();
<font color="#CC0000">// print out cookies</font>
Cookie[] cookies = request.getCookies();
for (int i = 0; i < cookies.length; i++) {
Cookie c = cookies[i];
String name = c.getName();
String value = c.getValue();
out.println(name + "<font color="#009900"> = </font>" + value);
}
<font color="#CC0000">// set a cookie</font>
String name = request.getParameter("<font color="#009900">cookieName</font>");
if (name != null && name.length() > 0) {
String value = request.getParameter("<font color="#009900">cookieValue</font>");
Cookie c = new Cookie(name, value);
response.addCookie(c);
}
}
}</pre>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/servlets/helloworld.html
Index: helloworld.html
===================================================================
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<p><font color="#0000FF"><a href="../servlet/HelloWorldExample"><img src="../images/execute.gif" align="right" border="0"></a><a href="index.html"><img src="../images/return.gif" width="24" height="24" align="right" border="0"></a></font></p>
<h3>Source Code for HelloWorld Example<font color="#0000FF"><br>
</font> </h3>
<font color="#0000FF"></font>
<pre><font color="#0000FF">import</font> java.io.*;
<font color="#0000FF">import</font> javax.servlet.*;
<font color="#0000FF">import</font> javax.servlet.http.*;
<font color="#0000FF">public class</font> HelloWorld <font color="#0000FF">extends</font> HttpServlet {
<font color="#0000FF">public void</font> doGet(HttpServletRequest request, HttpServletResponse response)
<font color="#0000FF">throws</font> IOException, ServletException
{
response.setContentType("<font color="#009900">text/html</font>");
PrintWriter out = response.getWriter();
out.println("<font color="#009900"><html></font>");
out.println("<font color="#009900"><body></font>");
out.println("<font color="#009900"><head></font>");
out.println("<font color="#009900"><title>Hello World!</title></font>");
out.println("<font color="#009900"></head></font>");
out.println("<font color="#009900"><body></font>");
out.println("<font color="#009900"><h1>Hello World!</h1></font>");
out.println("<font color="#009900"></body></font>");
out.println("<font color="#009900"></html></font>");
}
}</pre>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/servlets/index.html
Index: index.html
===================================================================
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Mozilla/4.61 [en] (WinNT; I) [Netscape]">
<meta name="Author" content="Anil K. Vijendran">
<title>Servlet Examples</title>
</head>
<body bgcolor="#FFFFFF">
<b><font face="Arial, Helvetica, sans-serif"><font size=+2>Servlet
Examples with Code</font></font></b>
<p>This is a collection of examples which demonstrate some of the more
frequently used parts of the Servlet API. Familiarity with the Java(tm)
Programming Language is assumed.
<p>These examples will only work when viewed via an http URL. They will
not work if you are viewing these pages via a "file://..." URL. Please
refer to the <i>README</i> file provide with this Tomcat release regarding
how to configure and start the provided web server.
<p>Wherever you see a form, enter some data and see how the servlet reacts.
When playing with the Cookie and Session Examples, jump back to the Headers
Example to see exactly what your browser is sending the server.
<p>To navigate your way through the examples, the following icons will
help:
<br>
<table BORDER=0 CELLSPACING=5 WIDTH="85%" >
<tr VALIGN=TOP>
<td WIDTH="30"><img SRC="../images/execute.gif" ></td>
<td>Execute the example</td>
</tr>
<tr VALIGN=TOP>
<td WIDTH="30"><img SRC="../images/code.gif" height=24 width=24></td>
<td>Look at the source code for the example</td>
</tr>
<tr VALIGN=TOP>
<td WIDTH="30"><img SRC="../images/return.gif" height=24 width=24></td>
<td>Return to this screen</td>
</tr>
</table>
<p>Tip: To see the cookie interactions with your browser, try turning on
the "notify when setting a cookie" option in your browser preferences.
This will let you see when a session is created and give some feedback
when looking at the cookie demo.
<br>
<table BORDER=0 CELLSPACING=5 WIDTH="85%" >
<tr VALIGN=TOP>
<td>Hello World</td>
<td VALIGN=TOP WIDTH="30%"><a href="../servlet/HelloWorldExample"><img SRC="../images/execute.gif" HSPACE=4 BORDER=0 align=TOP></a><a href="../servlet/HelloWorldExample">Execute</a></td>
<td WIDTH="30%"><a href="helloworld.html"><img SRC="../images/code.gif" HSPACE=4 BORDER=0 height=24 width=24 align=TOP></a><a href="helloworld.html">Source</a></td>
</tr>
<tr VALIGN=TOP>
<td>Request Info</td>
<td WIDTH="30%"><a href="../servlet/RequestInfoExample"><img SRC="../images/execute.gif" HSPACE=4 BORDER=0 align=TOP></a><a href="../servlet/RequestInfoExample">Execute</a></td>
<td WIDTH="30%"><a href="reqinfo.html"><img SRC="../images/code.gif" HSPACE=4 BORDER=0 height=24 width=24 align=TOP></a><a href="reqinfo.html">Source</a></td>
</tr>
<tr VALIGN=TOP>
<td>Request Headers</td>
<td WIDTH="30%"><a href="../servlet/RequestHeaderExample"><img SRC="../images/execute.gif" HSPACE=4 BORDER=0 align=TOP></a><a href="../servlet/RequestHeaderExample">Execute</a></td>
<td WIDTH="30%"><a href="reqheaders.html"><img SRC="../images/code.gif" HSPACE=4 BORDER=0 height=24 width=24 align=TOP></a><a href="reqheaders.html">Source</a></td>
</tr>
<tr VALIGN=TOP>
<td>Request Parameters</td>
<td WIDTH="30%"><a href="../servlet/RequestParamExample"><img SRC="../images/execute.gif" HSPACE=4 BORDER=0 align=TOP></a><a href="../servlet/RequestParamExample">Execute</a></td>
<td WIDTH="30%"><a href="reqparams.html"><img SRC="../images/code.gif" HSPACE=4 BORDER=0 height=24 width=24 align=TOP></a><a href="reqparams.html">Source</a></td>
</tr>
<tr VALIGN=TOP>
<td>Cookies</td>
<td WIDTH="30%"><a href="../servlet/CookieExample"><img SRC="../images/execute.gif" HSPACE=4 BORDER=0 align=TOP></a><a href="../servlet/CookieExample">Execute</a></td>
<td WIDTH="30%"><a href="cookies.html"><img SRC="../images/code.gif" HSPACE=4 BORDER=0 height=24 width=24 align=TOP></a><a href="cookies.html">Source</a></td>
</tr>
<tr VALIGN=TOP>
<td>Sessions</td>
<td WIDTH="30%"><a href="../servlet/SessionExample"><img SRC="../images/execute.gif" HSPACE=4 BORDER=0 align=TOP></a><a href="../servlet/SessionExample">Execute</a></td>
<td WIDTH="30%"><a href="sessions.html"><img SRC="../images/code.gif" HSPACE=4 BORDER=0 height=24 width=24 align=TOP></a><a href="sessions.html">Source</a></td>
</tr>
</table>
<p>Note: The source code for these examples does not contain all of the
source code that is actually in the example, only the important sections
of code. Code not important to understand the example has been removed
for clarity.
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/servlets/reqheaders.html
Index: reqheaders.html
===================================================================
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<p><font color="#0000FF"><a href="../servlet/RequestHeaderExample"><img src="../images/execute.gif" align="right" border="0"></a><a href="index.html"><img src="../images/return.gif" width="24" height="24" align="right" border="0"></a></font></p>
<h3>Source Code for RequestHeader Example<font color="#0000FF"><br>
</font> </h3>
<font color="#0000FF"></font>
<pre><font color="#0000FF">import</font> java.io.*;
<font color="#0000FF">import</font> java.util.*;
<font color="#0000FF">import</font> javax.servlet.*;
<font color="#0000FF">import</font> javax.servlet.http.*;
<font color="#0000FF">public class</font> RequestHeaderExample <font color="#0000FF">extends</font> HttpServlet {
<font color="#0000FF">public void</font> doGet(HttpServletRequest request, HttpServletResponse response)
<font color="#0000FF">throws</font> IOException, ServletException
{
response.setContentType("<font color="#009900">text/html</font>");
PrintWriter out = response.getWriter();
Enumeration e = request.getHeaderNames();
while (e.hasMoreElements()) {
String name = (String)e.nextElement();
String value = request.getHeader(name);
out.println(name + "<font color="#009900"> = </font>" + value);
}
}
}</pre>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/servlets/reqinfo.html
Index: reqinfo.html
===================================================================
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<p><font color="#0000FF"><a href="../servlet/RequestInfoExample"><img src="../images/execute.gif" align="right" border="0"></a><a href="index.html"><img src="../images/return.gif" width="24" height="24" align="right" border="0"></a></font></p>
<h3>Source Code for Request Info Example<font color="#0000FF"><br>
</font> </h3>
<font color="#0000FF"></font>
<pre><font color="#0000FF">import</font> java.io.*;
<font color="#0000FF">import</font> javax.servlet.*;
<font color="#0000FF">import</font> javax.servlet.http.*;
<font color="#0000FF">public class</font> RequestInfo <font color="#0000FF">extends</font> HttpServlet {
<font color="#0000FF">public void</font> doGet(HttpServletRequest request, HttpServletResponse response)
<font color="#0000FF">throws</font> IOException, ServletException
{
response.setContentType("<font color="#009900">text/html</font>");
PrintWriter out = response.getWriter();
out.println("<font color="#009900"><html></font>");
out.println("<font color="#009900"><body></font>");
out.println("<font color="#009900"><head></font>");
out.println("<font color="#009900"><title>Request Information Example</title></font>");
out.println("<font color="#009900"></head></font>");
out.println("<font color="#009900"><body></font>");
out.println("<font color="#009900"><h3>Request Information Example</h3></font>");
out.println("<font color="#009900">Method: </font>" + request.getMethod());
out.println("<font color="#009900">Request URI: </font>" + request.getRequestURI());
out.println("<font color="#009900">Protocol: </font>" + request.getProtocol());
out.println("<font color="#009900">PathInfo: </font>" + request.getPathInfo());
out.println("<font color="#009900">Remote Address: </font>" + request.getRemoteAddr());
out.println("<font color="#009900"></body></font>");
out.println("<font color="#009900"></html></font>");
}
<font color="#FF0000"> /**
* We are going to perform the same operations for POST requests
* as for GET methods, so this method just sends the request to
* the doGet method.
*/</font>
<font color="#0000FF">public void</font> doPost(HttpServletRequest request, HttpServletResponse response)
<font color="#0000FF">throws</font> IOException, ServletException
{
doGet(request, response);
}
}</pre>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/servlets/reqparams.html
Index: reqparams.html
===================================================================
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<p><font color="#0000FF"><a href="../servlet/RequestParamExample"><img src="../images/execute.gif" align="right" border="0"></a><a href="index.html"><img src="../images/return.gif" width="24" height="24" align="right" border="0"></a></font></p>
<h3>Source Code for Request Parameter Example<font color="#0000FF"><br>
</font> </h3>
<font color="#0000FF"></font>
<pre><font color="#0000FF">import</font> java.io.*;
<font color="#0000FF">import</font> java.util.*;
<font color="#0000FF">import</font> javax.servlet.*;
<font color="#0000FF">import</font> javax.servlet.http.*;
<font color="#0000FF">public class</font> RequestParamExample <font color="#0000FF">extends</font> HttpServlet {
<font color="#0000FF">public void</font> doGet(HttpServletRequest request, HttpServletResponse response)
<font color="#0000FF">throws</font> IOException, ServletException
{
response.setContentType("<font color="#009900">text/html</font>");
PrintWriter out = response.getWriter();
out.println("GET Request. No Form Data Posted");
}
<font color="#0000FF">public void</font> doPost(HttpServletRequest request, HttpServletResponse res)
<font color="#0000FF">throws</font> IOException, ServletException
{
Enumeration e = request.getParameterNames();
PrintWriter out = res.getWriter ();
while (e.hasMoreElements()) {
String name = (String)e.nextElement();
String value = request.getParameter(name);
out.println(name + "<font color="#009900"> = </font>" + value);
}
}
}</pre>
</body>
</html>
1.1 jakarta-tomcat-4.0/webapps/examples/servlets/sessions.html
Index: sessions.html
===================================================================
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<p><font color="#0000FF"><a href="../servlet/SessionExample"><img src="../images/execute.gif" align="right" border="0"></a><a href="index.html"><img src="../images/return.gif" width="24" height="24" align="right" border="0"></a></font></p>
<h3>Source Code for Session Example<font color="#0000FF"><br>
</font> </h3>
<font color="#0000FF"></font>
<pre><font color="#0000FF">import</font> java.io.*;
<font color="#0000FF">import</font> java.util.*;
<font color="#0000FF">import</font> javax.servlet.*;
<font color="#0000FF">import</font> javax.servlet.http.*;
<font color="#0000FF">public class</font> SessionExample <font color="#0000FF">extends</font> HttpServlet {
<font color="#0000FF">public void</font> doGet(HttpServletRequest request, HttpServletResponse response)
<font color="#0000FF">throws</font> IOException, ServletException
{
response.setContentType("<font color="#009900">text/html</font>");
PrintWriter out = response.getWriter();
HttpSession session = request.getSession(true);
<font color="#CC0000">// print session info</font>
Date created = new Date(session.getCreationTime());
Date accessed = new Date(session.getLastAccessedTime());
out.println("<font color="#009900">ID </font>" + session.getId());
out.println("<font color="#009900">Created: </font>" + created);
out.println("<font color="#009900">Last Accessed: </font>" + accessed);
<font color="#CC0000">// set session info if needed</font>
String dataName = request.getParameter("<font color="#009900">dataName</font>");
if (dataName != null && dataName.length() > 0) {
String dataValue = request.getParameter("<font color="#009900">dataValue</font>");
session.setAttribute(dataName, dataValue);
}
// print session contents
Enumeration e = session.getAttributeNames();
while (e.hasMoreElements()) {
String name = (String)e.nextElement();
String value = session.getAttribute(name).toString();
out.println(name + " <font color="#009900">= </font>" + value);
}
}
}</pre>
</body>
</html>