From: remm Date: Mon, 29 May 2006 11:51:34 +0000 (+0000) Subject: - Add examples webapp. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=0e9227e4585fc1b4ab37c78ae603a409557921b7;p=tomcat7.0 - Add examples webapp. - New chat example, which doesn't work properly yet (I suck at HTML). For some reason, it works with a telnet, but not with a browser, which doesn't do any rendering until the whole page is received. git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@410080 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/webapps/examples/WEB-INF/classes/CookieExample.java b/webapps/examples/WEB-INF/classes/CookieExample.java new file mode 100644 index 000000000..a301ed9b2 --- /dev/null +++ b/webapps/examples/WEB-INF/classes/CookieExample.java @@ -0,0 +1,121 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +/* $Id: CookieExample.java 267129 2004-03-18 16:40:35Z jfarcand $ + * + */ + +import java.io.*; +import java.text.*; +import java.util.*; +import javax.servlet.*; +import javax.servlet.http.*; + +import util.HTMLFilter; + +/** + * Example servlet showing request headers + * + * @author James Duncan Davidson + */ + +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(""); + out.println(""); + out.println(""); + + String title = rb.getString("cookies.title"); + out.println("" + title + ""); + out.println(""); + out.println(""); + + // relative links + + // XXX + // making these absolute till we work out the + // addition of a PathInfo issue + + out.println(""); + out.println("\"view"); + out.println(""); + out.println("\"return\""); + + out.println("

" + title + "

"); + + Cookie[] cookies = request.getCookies(); + if ((cookies != null) && (cookies.length > 0)) { + out.println(rb.getString("cookies.cookies") + "
"); + for (int i = 0; i < cookies.length; i++) { + Cookie cookie = cookies[i]; + out.print("Cookie Name: " + HTMLFilter.filter(cookie.getName()) + + "
"); + out.println(" Cookie Value: " + + HTMLFilter.filter(cookie.getValue()) + + "

"); + } + } 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("

"); + out.println(rb.getString("cookies.set") + "
"); + out.print(rb.getString("cookies.name") + " " + + HTMLFilter.filter(cookieName) + "
"); + out.print(rb.getString("cookies.value") + " " + + HTMLFilter.filter(cookieValue)); + } + + out.println("

"); + out.println(rb.getString("cookies.make-cookie") + "
"); + out.print("

"); + out.print(rb.getString("cookies.name") + " "); + out.println("
"); + out.print(rb.getString("cookies.value") + " "); + out.println("
"); + out.println("
"); + + + out.println(""); + out.println(""); + } + + public void doPost(HttpServletRequest request, + HttpServletResponse response) + throws IOException, ServletException + { + doGet(request, response); + } + +} + + diff --git a/webapps/examples/WEB-INF/classes/HelloWorldExample.java b/webapps/examples/WEB-INF/classes/HelloWorldExample.java new file mode 100644 index 000000000..7467297e2 --- /dev/null +++ b/webapps/examples/WEB-INF/classes/HelloWorldExample.java @@ -0,0 +1,75 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +/* $Id: HelloWorldExample.java 267129 2004-03-18 16:40:35Z jfarcand $ + * + */ + +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(""); + out.println(""); + + String title = rb.getString("helloworld.title"); + + out.println("" + title + ""); + out.println(""); + out.println(""); + + // 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(""); + out.println("\"view"); + out.println(""); + out.println("\"return\""); + out.println("

" + title + "

"); + out.println(""); + out.println(""); + } +} + + + diff --git a/webapps/examples/WEB-INF/classes/LocalStrings.properties b/webapps/examples/WEB-INF/classes/LocalStrings.properties new file mode 100644 index 000000000..f41c061cd --- /dev/null +++ b/webapps/examples/WEB-INF/classes/LocalStrings.properties @@ -0,0 +1,52 @@ +# Copyright 2004 The Apache Software Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# $Id: LocalStrings.properties 267129 2004-03-18 16:40:35Z jfarcand $ + +# 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: diff --git a/webapps/examples/WEB-INF/classes/LocalStrings_en.properties b/webapps/examples/WEB-INF/classes/LocalStrings_en.properties new file mode 100644 index 000000000..9087bddd9 --- /dev/null +++ b/webapps/examples/WEB-INF/classes/LocalStrings_en.properties @@ -0,0 +1,52 @@ +# Copyright 2004 The Apache Software Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# $Id: LocalStrings_en.properties 267129 2004-03-18 16:40:35Z jfarcand $ + +# 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: diff --git a/webapps/examples/WEB-INF/classes/LocalStrings_es.properties b/webapps/examples/WEB-INF/classes/LocalStrings_es.properties new file mode 100644 index 000000000..78b897c68 --- /dev/null +++ b/webapps/examples/WEB-INF/classes/LocalStrings_es.properties @@ -0,0 +1,52 @@ +# Copyright 2004 The Apache Software Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# $Id: LocalStrings_es.properties 267129 2004-03-18 16:40:35Z jfarcand $ +# +# 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: diff --git a/webapps/examples/WEB-INF/classes/LocalStrings_fr.properties b/webapps/examples/WEB-INF/classes/LocalStrings_fr.properties new file mode 100644 index 000000000..569443a3b --- /dev/null +++ b/webapps/examples/WEB-INF/classes/LocalStrings_fr.properties @@ -0,0 +1,52 @@ +# Copyright 2004 The Apache Software Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# $Id: LocalStrings_fr.properties 267129 2004-03-18 16:40:35Z jfarcand $ + +# Default localized resources for example servlets +# This locale is fr_FR + +helloworld.title=Salut le Monde! + +requestinfo.title=Exemple d''information sur la requête +requestinfo.label.method=Méthode: +requestinfo.label.requesturi=URI de requête: +requestinfo.label.protocol=Protocole: +requestinfo.label.pathinfo=Info de chemin: +requestinfo.label.remoteaddr=Adresse distante: + +requestheader.title=Exemple d''information sur les entête de requête + +requestparams.title=Exemple de requête avec paramêtres +requestparams.params-in-req=Paramêtres dans la requête: +requestparams.no-params=Pas de paramêtre, merci dans saisir quelqu'uns +requestparams.firstname=Prénom: +requestparams.lastname=Nom: + +cookies.title=Exemple d''utilisation de Cookies +cookies.cookies=Votre navigateur retourne les cookies suivant: +cookies.no-cookies=Votre navigateur ne retourne aucun cookie +cookies.make-cookie=Création d''un cookie à retourner à votre navigateur +cookies.name=Nom: +cookies.value=Valeur: +cookies.set=Vous venez d''envoyer le cookie suivant à votre navigateur: + +sessions.title=Exemple de Sessions +sessions.id=ID de Session: +sessions.created=Crée le: +sessions.lastaccessed=Dernier accès: +sessions.data=Les données existantes dans votre session: +sessions.adddata=Ajouter des données à votre session +sessions.dataname=Nom de l''Attribut de Session: +sessions.datavalue=Valeur de l''Attribut de Session: diff --git a/webapps/examples/WEB-INF/classes/LocalStrings_pt.properties b/webapps/examples/WEB-INF/classes/LocalStrings_pt.properties new file mode 100644 index 000000000..9417ed7c9 --- /dev/null +++ b/webapps/examples/WEB-INF/classes/LocalStrings_pt.properties @@ -0,0 +1,52 @@ +# Copyright 2004 The Apache Software Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# $Id: LocalStrings_pt.properties 267143 2004-08-24 18:38:35Z jfarcand $ + +# Default localized resources for example servlets +# This locale is pt_PT + +helloworld.title=Ola Mundo! + +requestinfo.title=Exemplo da Informacao do Pedido +requestinfo.label.method=Metodo: +requestinfo.label.requesturi=URI do Pedido: +requestinfo.label.protocol=Protocolo: +requestinfo.label.pathinfo=Informacao do Caminho: +requestinfo.label.remoteaddr=Endereco Remoto: + +requestheader.title=Exemplo da Cebeceira do Pedido + +requestparams.title=Examplo de Parametros do Pedido +requestparams.params-in-req=Parametros neste pedido: +requestparams.no-params=Sem Parametros, Por favor entre alguns +requestparams.firstname=Primeiro Nome: +requestparams.lastname=Apelido: + +cookies.title=CExamplo de Cookies +cookies.cookies=O se browser esta a enviar os seguintes cookies: +cookies.no-cookies=O seu browser nao esta a enviar nenhuns cookies +cookies.make-cookie=Crie um cookie para enviar para o seu browser +cookies.name=Nome: +cookies.value=Valor: +cookies.set=Acabou de enviar o seguinte cookie para o seu browser: + +sessions.title=Examplo de sessoes +sessions.id=Identificador da Sessao: +sessions.created=Criada: +sessions.lastaccessed=Ultima vez acedida: +sessions.data=Os seguintes dados fazem parte da sua sessao: +sessions.adddata=Adicione data a sua sessao +sessions.dataname=Nome do atributo da sessao: +sessions.datavalue=Valor do atributo da Sessao: diff --git a/webapps/examples/WEB-INF/classes/RequestHeaderExample.java b/webapps/examples/WEB-INF/classes/RequestHeaderExample.java new file mode 100644 index 000000000..36e967179 --- /dev/null +++ b/webapps/examples/WEB-INF/classes/RequestHeaderExample.java @@ -0,0 +1,90 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +/* $Id: RequestHeaderExample.java 267129 2004-03-18 16:40:35Z jfarcand $ + * + */ + +import java.io.*; +import java.text.*; +import java.util.*; +import javax.servlet.*; +import javax.servlet.http.*; + +import util.HTMLFilter; + +/** + * Example servlet showing request headers + * + * @author James Duncan Davidson + */ + +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(""); + out.println(""); + out.println(""); + + String title = rb.getString("requestheader.title"); + out.println("" + title + ""); + out.println(""); + out.println(""); + + // all links relative + + // XXX + // making these absolute till we work out the + // addition of a PathInfo issue + + out.println(""); + out.println("\"view"); + out.println(""); + out.println("\"return\""); + + out.println("

" + title + "

"); + out.println(""); + Enumeration e = request.getHeaderNames(); + while (e.hasMoreElements()) { + String headerName = (String)e.nextElement(); + String headerValue = request.getHeader(headerName); + out.println(""); + } + out.println("
"); + out.println(HTMLFilter.filter(headerName)); + out.println(""); + out.println(HTMLFilter.filter(headerValue)); + out.println("
"); + } + + public void doPost(HttpServletRequest request, + HttpServletResponse response) + throws IOException, ServletException + { + doGet(request, response); + } + +} + diff --git a/webapps/examples/WEB-INF/classes/RequestInfoExample.java b/webapps/examples/WEB-INF/classes/RequestInfoExample.java new file mode 100644 index 000000000..966af3c9b --- /dev/null +++ b/webapps/examples/WEB-INF/classes/RequestInfoExample.java @@ -0,0 +1,114 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +/* $Id: RequestInfoExample.java 267129 2004-03-18 16:40:35Z jfarcand $ + * + */ + +import java.io.*; +import java.text.*; +import java.util.*; +import javax.servlet.*; +import javax.servlet.http.*; + +import util.HTMLFilter; + +/** + * Example servlet showing request information. + * + * @author James Duncan Davidson + */ + +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(""); + out.println(""); + out.println(""); + + String title = rb.getString("requestinfo.title"); + out.println("" + title + ""); + out.println(""); + out.println(""); + + // 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(""); + out.println("\"view"); + out.println(""); + out.println("\"return\""); + + out.println("

" + title + "

"); + out.println("
"); + out.println(rb.getString("requestinfo.label.method")); + out.println(""); + out.println(request.getMethod()); + out.println("
"); + out.println(rb.getString("requestinfo.label.requesturi")); + out.println(""); + out.println(HTMLFilter.filter(request.getRequestURI())); + out.println("
"); + out.println(rb.getString("requestinfo.label.protocol")); + out.println(""); + out.println(request.getProtocol()); + out.println("
"); + out.println(rb.getString("requestinfo.label.pathinfo")); + out.println(""); + out.println(HTMLFilter.filter(request.getPathInfo())); + out.println("
"); + out.println(rb.getString("requestinfo.label.remoteaddr")); + + String cipherSuite= + (String)request.getAttribute("javax.servlet.request.cipher_suite"); + out.println(""); + out.println(request.getRemoteAddr()); + out.println("
"); + + if(cipherSuite!=null){ + out.println(""); + out.println("SSLCipherSuite:"); + out.println(""); + out.println(""); + out.println(request.getAttribute("javax.servlet.request.cipher_suite")); + out.println(""); + } + + } + + public void doPost(HttpServletRequest request, + HttpServletResponse response) + throws IOException, ServletException + { + doGet(request, response); + } + +} + diff --git a/webapps/examples/WEB-INF/classes/RequestParamExample.java b/webapps/examples/WEB-INF/classes/RequestParamExample.java new file mode 100644 index 000000000..b909e62b8 --- /dev/null +++ b/webapps/examples/WEB-INF/classes/RequestParamExample.java @@ -0,0 +1,106 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +/* $Id: RequestParamExample.java 267129 2004-03-18 16:40:35Z jfarcand $ + * + */ + +import java.io.*; +import java.text.*; +import java.util.*; +import javax.servlet.*; +import javax.servlet.http.*; + +import util.HTMLFilter; + +/** + * Example servlet showing request headers + * + * @author James Duncan Davidson + */ + +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(""); + out.println(""); + out.println(""); + + String title = rb.getString("requestparams.title"); + out.println("" + title + ""); + out.println(""); + out.println(""); + + // 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(""); + out.println("\"view"); + out.println(""); + out.println("\"return\""); + + out.println("

" + title + "

"); + String firstName = request.getParameter("firstname"); + String lastName = request.getParameter("lastname"); + out.println(rb.getString("requestparams.params-in-req") + "
"); + if (firstName != null || lastName != null) { + out.println(rb.getString("requestparams.firstname")); + out.println(" = " + HTMLFilter.filter(firstName) + "
"); + out.println(rb.getString("requestparams.lastname")); + out.println(" = " + HTMLFilter.filter(lastName)); + } else { + out.println(rb.getString("requestparams.no-params")); + } + out.println("

"); + out.print("

"); + out.println(rb.getString("requestparams.firstname")); + out.println(""); + out.println("
"); + out.println(rb.getString("requestparams.lastname")); + out.println(""); + out.println("
"); + out.println(""); + out.println("
"); + + out.println(""); + out.println(""); + } + + public void doPost(HttpServletRequest request, + HttpServletResponse response) + throws IOException, ServletException + { + doGet(request, response); + } + +} diff --git a/webapps/examples/WEB-INF/classes/SessionExample.java b/webapps/examples/WEB-INF/classes/SessionExample.java new file mode 100644 index 000000000..6d8c23ef5 --- /dev/null +++ b/webapps/examples/WEB-INF/classes/SessionExample.java @@ -0,0 +1,140 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +/* $Id: SessionExample.java 267129 2004-03-18 16:40:35Z jfarcand $ + * + */ + +import java.io.*; +import java.text.*; +import java.util.*; +import javax.servlet.*; +import javax.servlet.http.*; + +import util.HTMLFilter; + +/** + * Example servlet showing request headers + * + * @author James Duncan Davidson + */ + +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(""); + out.println(""); + out.println(""); + + String title = rb.getString("sessions.title"); + out.println("" + title + ""); + out.println(""); + out.println(""); + + // 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(""); + out.println("\"view"); + out.println(""); + out.println("\"return\""); + + out.println("

" + title + "

"); + + HttpSession session = request.getSession(true); + out.println(rb.getString("sessions.id") + " " + session.getId()); + out.println("
"); + out.println(rb.getString("sessions.created") + " "); + out.println(new Date(session.getCreationTime()) + "
"); + 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("

"); + out.println(rb.getString("sessions.data") + "
"); + Enumeration names = session.getAttributeNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + String value = session.getAttribute(name).toString(); + out.println(HTMLFilter.filter(name) + " = " + + HTMLFilter.filter(value) + "
"); + } + + out.println("

"); + out.print("

"); + out.println(rb.getString("sessions.dataname")); + out.println(""); + out.println("
"); + out.println(rb.getString("sessions.datavalue")); + out.println(""); + out.println("
"); + out.println(""); + out.println("
"); + + out.println("

GET based form:
"); + out.print("

"); + out.println(rb.getString("sessions.dataname")); + out.println(""); + out.println("
"); + out.println(rb.getString("sessions.datavalue")); + out.println(""); + out.println("
"); + out.println(""); + out.println("
"); + + out.print("

URL encoded "); + + out.println(""); + out.println(""); + + out.println(""); + out.println(""); + } + + public void doPost(HttpServletRequest request, + HttpServletResponse response) + throws IOException, ServletException + { + doGet(request, response); + } + +} diff --git a/webapps/examples/WEB-INF/classes/cal/Entries.java b/webapps/examples/WEB-INF/classes/cal/Entries.java new file mode 100644 index 000000000..f76259028 --- /dev/null +++ b/webapps/examples/WEB-INF/classes/cal/Entries.java @@ -0,0 +1,72 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +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= 0) { + String descr = request.getParameter ("description"); + ((Entry)entries.get(time[index])).setDescription (descr); + } + } + +} + + + + + + + + + + + + + diff --git a/webapps/examples/WEB-INF/classes/cal/Entry.java b/webapps/examples/WEB-INF/classes/cal/Entry.java new file mode 100644 index 000000000..035eda075 --- /dev/null +++ b/webapps/examples/WEB-INF/classes/cal/Entry.java @@ -0,0 +1,54 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +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; + } + +} + + + + + diff --git a/webapps/examples/WEB-INF/classes/cal/JspCalendar.java b/webapps/examples/WEB-INF/classes/cal/JspCalendar.java new file mode 100644 index 000000000..14063fdba --- /dev/null +++ b/webapps/examples/WEB-INF/classes/cal/JspCalendar.java @@ -0,0 +1,154 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +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); + } +} + + + + + diff --git a/webapps/examples/WEB-INF/classes/cal/TableBean.java b/webapps/examples/WEB-INF/classes/cal/TableBean.java new file mode 100644 index 000000000..75cd59947 --- /dev/null +++ b/webapps/examples/WEB-INF/classes/cal/TableBean.java @@ -0,0 +1,101 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +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; + } +} + + + + + + diff --git a/webapps/examples/WEB-INF/classes/chat/ChatServlet.java b/webapps/examples/WEB-INF/classes/chat/ChatServlet.java new file mode 100644 index 000000000..1cd26293c --- /dev/null +++ b/webapps/examples/WEB-INF/classes/chat/ChatServlet.java @@ -0,0 +1,212 @@ +/* + * Copyright 2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package chat; + + +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintWriter; +import java.util.ArrayList; + +import org.apache.catalina.servlets.CometServlet; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + + +/** + * Helper class to implement Comet functionality. + */ +public class ChatServlet + extends CometServlet { + + protected ArrayList connections = + new ArrayList(); + protected MessageSender messageSender = null; + + public void init() throws ServletException { + messageSender = new MessageSender(); + Thread messageSenderThread = + new Thread(messageSender, "MessageSender[" + getServletContext().getContextPath() + "]"); + messageSenderThread.setDaemon(true); + messageSenderThread.start(); + } + + public void destroy() { + connections.clear(); + messageSender.stop(); + messageSender = null; + } + + public void begin(HttpServletRequest request, HttpServletResponse response) + throws IOException, ServletException { + super.begin(request, response); + log("Begin for session: " + request.getSession(true).getId()); + + PrintWriter writer = response.getWriter(); + writer.println(""); + writer.println("JSP Chat"); + writer.flush(); + + synchronized(connections) { + connections.add(response); + } + } + + public void end(HttpServletRequest request, HttpServletResponse response) + throws IOException, ServletException { + super.end(request, response); + log("End for session: " + request.getSession(true).getId()); + synchronized(connections) { + connections.remove(response); + } + + PrintWriter writer = response.getWriter(); + writer.println(""); + + } + + public void error(HttpServletRequest request, HttpServletResponse response) + throws IOException, ServletException { + log("Error for session: " + request.getSession(true).getId()); + end(request, response); + } + + public boolean read(HttpServletRequest request, HttpServletResponse response) + throws IOException, ServletException { + InputStream is = request.getInputStream(); + byte[] buf = new byte[512]; + do { + int n = is.read(buf); + if (n > 0) { + log("Read " + n + " bytes: " + new String(buf, 0, n) + + " for session: " + request.getSession(true).getId()); + } else if (n < 0) { + return false; + } + } while (is.available() > 0); + return true; + } + + protected void service(HttpServletRequest request, HttpServletResponse response) + throws IOException, ServletException { + String action = request.getParameter("action"); + if (action != null) { + if ("login".equals(action)) { + String nickname = request.getParameter("nickname"); + request.getSession(true).setAttribute("nickname", nickname); + response.sendRedirect("post.jsp"); + } else { + String nickname = (String) request.getSession(true).getAttribute("nickname"); + String message = request.getParameter("message"); + messageSender.send(nickname, message); + response.sendRedirect("post.jsp"); + } + } else { + if (request.getSession(true).getAttribute("nickname") == null) { + // Redirect to "login" + response.sendRedirect("login.jsp"); + } else { + // Request to view the chet, so use Comet + super.service(request, response); + } + } + } + + + /** + * Poller class. + */ + public class MessageSender implements Runnable { + + protected boolean running = true; + protected ArrayList messages = new ArrayList(); + + public MessageSender() { + } + + public void stop() { + running = false; + } + + /** + * Add specified socket and associated pool to the poller. The socket will + * be added to a temporary array, and polled first after a maximum amount + * of time equal to pollTime (in most cases, latency will be much lower, + * however). + * + * @param socket to add to the poller + */ + public void send(String user, String message) { + synchronized (messages) { + messages.add("[" + user + "]: " + message); + messages.notify(); + } + } + + /** + * The background thread that listens for incoming TCP/IP connections and + * hands them off to an appropriate processor. + */ + public void run() { + + // Loop until we receive a shutdown command + while (running) { + // Loop if endpoint is paused + + if (messages.size() == 0) { + try { + synchronized (messages) { + messages.wait(); + } + } catch (InterruptedException e) { + // Ignore + } + } + + synchronized (connections) { + String[] pendingMessages = null; + synchronized (messages) { + pendingMessages = messages.toArray(new String[0]); + messages.clear(); + } + for (int i = 0; i < connections.size(); i++) { + try { + PrintWriter writer = connections.get(i).getWriter(); + for (int j = 0; j < pendingMessages.length; j++) { + // FIXME: Add HTML filtering + writer.println(pendingMessages[j] + "
"); + } + writer.flush(); + } catch (IOException e) { + log("IOExeption sending message", e); + } + } + } + + } + + } + + } + + + + +} diff --git a/webapps/examples/WEB-INF/classes/checkbox/CheckTest.java b/webapps/examples/WEB-INF/classes/checkbox/CheckTest.java new file mode 100644 index 000000000..ad6d2ed64 --- /dev/null +++ b/webapps/examples/WEB-INF/classes/checkbox/CheckTest.java @@ -0,0 +1,30 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +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; + } +} diff --git a/webapps/examples/WEB-INF/classes/colors/ColorGameBean.java b/webapps/examples/WEB-INF/classes/colors/ColorGameBean.java new file mode 100644 index 000000000..1235b98b1 --- /dev/null +++ b/webapps/examples/WEB-INF/classes/colors/ColorGameBean.java @@ -0,0 +1,114 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +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; + } +} + diff --git a/webapps/examples/WEB-INF/classes/compressionFilters/CompressionFilter.java b/webapps/examples/WEB-INF/classes/compressionFilters/CompressionFilter.java new file mode 100644 index 000000000..718865900 --- /dev/null +++ b/webapps/examples/WEB-INF/classes/compressionFilters/CompressionFilter.java @@ -0,0 +1,218 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package compressionFilters; + +import java.io.IOException; +import java.util.Enumeration; +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + + +/** + * Implementation of javax.servlet.Filter used to compress + * the ServletResponse if it is bigger than a threshold. + * + * @author Amy Roh + * @author Dmitri Valdin + * @version $Revision: 267129 $, $Date: 2004-03-18 17:40:35 +0100 (jeu., 18 mars 2004) $ + */ + +public class CompressionFilter implements Filter{ + + /** + * The filter configuration object we are associated with. If this value + * is null, this filter instance is not currently configured. + */ + private FilterConfig config = null; + + /** + * Minimal reasonable threshold + */ + private int minThreshold = 128; + + + /** + * The threshold number to compress + */ + protected int compressionThreshold; + + /** + * Debug level for this filter + */ + private int debug = 0; + + /** + * Place this filter into service. + * + * @param filterConfig The filter configuration object + */ + + public void init(FilterConfig filterConfig) { + + config = filterConfig; + if (filterConfig != null) { + String value = filterConfig.getInitParameter("debug"); + if (value!=null) { + debug = Integer.parseInt(value); + } else { + debug = 0; + } + String str = filterConfig.getInitParameter("compressionThreshold"); + if (str!=null) { + compressionThreshold = Integer.parseInt(str); + if (compressionThreshold != 0 && compressionThreshold < minThreshold) { + if (debug > 0) { + System.out.println("compressionThreshold should be either 0 - no compression or >= " + minThreshold); + System.out.println("compressionThreshold set to " + minThreshold); + } + compressionThreshold = minThreshold; + } + } else { + compressionThreshold = 0; + } + + } else { + compressionThreshold = 0; + } + + } + + /** + * Take this filter out of service. + */ + public void destroy() { + + this.config = null; + + } + + /** + * The doFilter method of the Filter is called by the container + * each time a request/response pair is passed through the chain due + * to a client request for a resource at the end of the chain. + * The FilterChain passed into this method allows the Filter to pass on the + * request and response to the next entity in the chain.

+ * This method first examines the request to check whether the client support + * compression.
+ * It simply just pass the request and response if there is no support for + * compression.
+ * If the compression support is available, it creates a + * CompressionServletResponseWrapper object which compresses the content and + * modifies the header if the content length is big enough. + * It then invokes the next entity in the chain using the FilterChain object + * (chain.doFilter()),
+ **/ + + public void doFilter ( ServletRequest request, ServletResponse response, + FilterChain chain ) throws IOException, ServletException { + + if (debug > 0) { + System.out.println("@doFilter"); + } + + if (compressionThreshold == 0) { + if (debug > 0) { + System.out.println("doFilter gets called, but compressionTreshold is set to 0 - no compression"); + } + chain.doFilter(request, response); + return; + } + + boolean supportCompression = false; + if (request instanceof HttpServletRequest) { + if (debug > 1) { + System.out.println("requestURI = " + ((HttpServletRequest)request).getRequestURI()); + } + + // Are we allowed to compress ? + String s = (String) ((HttpServletRequest)request).getParameter("gzip"); + if ("false".equals(s)) { + if (debug > 0) { + System.out.println("got parameter gzip=false --> don't compress, just chain filter"); + } + chain.doFilter(request, response); + return; + } + + Enumeration e = + ((HttpServletRequest)request).getHeaders("Accept-Encoding"); + while (e.hasMoreElements()) { + String name = (String)e.nextElement(); + if (name.indexOf("gzip") != -1) { + if (debug > 0) { + System.out.println("supports compression"); + } + supportCompression = true; + } else { + if (debug > 0) { + System.out.println("no support for compresion"); + } + } + } + } + + if (!supportCompression) { + if (debug > 0) { + System.out.println("doFilter gets called wo compression"); + } + chain.doFilter(request, response); + return; + } else { + if (response instanceof HttpServletResponse) { + CompressionServletResponseWrapper wrappedResponse = + new CompressionServletResponseWrapper((HttpServletResponse)response); + wrappedResponse.setDebugLevel(debug); + wrappedResponse.setCompressionThreshold(compressionThreshold); + if (debug > 0) { + System.out.println("doFilter gets called with compression"); + } + try { + chain.doFilter(request, wrappedResponse); + } finally { + wrappedResponse.finishResponse(); + } + return; + } + } + } + + /** + * Set filter config + * This function is equivalent to init. Required by Weblogic 6.1 + * + * @param filterConfig The filter configuration object + */ + public void setFilterConfig(FilterConfig filterConfig) { + init(filterConfig); + } + + /** + * Return filter config + * Required by Weblogic 6.1 + */ + public FilterConfig getFilterConfig() { + return config; + } + +} + diff --git a/webapps/examples/WEB-INF/classes/compressionFilters/CompressionFilterTestServlet.java b/webapps/examples/WEB-INF/classes/compressionFilters/CompressionFilterTestServlet.java new file mode 100644 index 000000000..d52f58cc2 --- /dev/null +++ b/webapps/examples/WEB-INF/classes/compressionFilters/CompressionFilterTestServlet.java @@ -0,0 +1,57 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package compressionFilters; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Enumeration; +import javax.servlet.*; +import javax.servlet.http.*; + +/** + * Very Simple test servlet to test compression filter + * @author Amy Roh + * @version $Revision: 267129 $, $Date: 2004-03-18 17:40:35 +0100 (jeu., 18 mars 2004) $ + */ + +public class CompressionFilterTestServlet extends HttpServlet { + + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + ServletOutputStream out = response.getOutputStream(); + response.setContentType("text/plain"); + + Enumeration e = ((HttpServletRequest)request).getHeaders("Accept-Encoding"); + while (e.hasMoreElements()) { + String name = (String)e.nextElement(); + out.println(name); + if (name.indexOf("gzip") != -1) { + out.println("gzip supported -- able to compress"); + } + else { + out.println("gzip not supported"); + } + } + + + out.println("Compression Filter Test Servlet"); + out.close(); + } + +} + diff --git a/webapps/examples/WEB-INF/classes/compressionFilters/CompressionResponseStream.java b/webapps/examples/WEB-INF/classes/compressionFilters/CompressionResponseStream.java new file mode 100644 index 000000000..70632f621 --- /dev/null +++ b/webapps/examples/WEB-INF/classes/compressionFilters/CompressionResponseStream.java @@ -0,0 +1,317 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package compressionFilters; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.zip.GZIPOutputStream; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; + + +/** + * Implementation of ServletOutputStream that works with + * the CompressionServletResponseWrapper implementation. + * + * @author Amy Roh + * @author Dmitri Valdin + * @version $Revision: 267129 $, $Date: 2004-03-18 17:40:35 +0100 (jeu., 18 mars 2004) $ + */ + +public class CompressionResponseStream + extends ServletOutputStream { + + + // ----------------------------------------------------------- Constructors + + + /** + * Construct a servlet output stream associated with the specified Response. + * + * @param response The associated response + */ + public CompressionResponseStream(HttpServletResponse response) throws IOException{ + + super(); + closed = false; + this.response = response; + this.output = response.getOutputStream(); + + } + + + // ----------------------------------------------------- Instance Variables + + + /** + * The threshold number which decides to compress or not. + * Users can configure in web.xml to set it to fit their needs. + */ + protected int compressionThreshold = 0; + + /** + * Debug level + */ + private int debug = 0; + + /** + * The buffer through which all of our output bytes are passed. + */ + protected byte[] buffer = null; + + /** + * The number of data bytes currently in the buffer. + */ + protected int bufferCount = 0; + + /** + * The underlying gzip output stream to which we should write data. + */ + protected GZIPOutputStream gzipstream = null; + + /** + * Has this stream been closed? + */ + protected boolean closed = false; + + /** + * The content length past which we will not write, or -1 if there is + * no defined content length. + */ + protected int length = -1; + + /** + * The response with which this servlet output stream is associated. + */ + protected HttpServletResponse response = null; + + /** + * The underlying servket output stream to which we should write data. + */ + protected ServletOutputStream output = null; + + + // --------------------------------------------------------- Public Methods + + /** + * Set debug level + */ + public void setDebugLevel(int debug) { + this.debug = debug; + } + + + /** + * Set the compressionThreshold number and create buffer for this size + */ + protected void setBuffer(int threshold) { + compressionThreshold = threshold; + buffer = new byte[compressionThreshold]; + if (debug > 1) { + System.out.println("buffer is set to "+compressionThreshold); + } + } + + /** + * Close this output stream, causing any buffered data to be flushed and + * any further output data to throw an IOException. + */ + public void close() throws IOException { + + if (debug > 1) { + System.out.println("close() @ CompressionResponseStream"); + } + if (closed) + throw new IOException("This output stream has already been closed"); + + if (gzipstream != null) { + flushToGZip(); + gzipstream.close(); + gzipstream = null; + } else { + if (bufferCount > 0) { + if (debug > 2) { + System.out.print("output.write("); + System.out.write(buffer, 0, bufferCount); + System.out.println(")"); + } + output.write(buffer, 0, bufferCount); + bufferCount = 0; + } + } + + output.close(); + closed = true; + + } + + + /** + * Flush any buffered data for this output stream, which also causes the + * response to be committed. + */ + public void flush() throws IOException { + + if (debug > 1) { + System.out.println("flush() @ CompressionResponseStream"); + } + if (closed) { + throw new IOException("Cannot flush a closed output stream"); + } + + if (gzipstream != null) { + gzipstream.flush(); + } + + } + + public void flushToGZip() throws IOException { + + if (debug > 1) { + System.out.println("flushToGZip() @ CompressionResponseStream"); + } + if (bufferCount > 0) { + if (debug > 1) { + System.out.println("flushing out to GZipStream, bufferCount = " + bufferCount); + } + writeToGZip(buffer, 0, bufferCount); + bufferCount = 0; + } + + } + + /** + * Write the specified byte to our output stream. + * + * @param b The byte to be written + * + * @exception IOException if an input/output error occurs + */ + public void write(int b) throws IOException { + + if (debug > 1) { + System.out.println("write "+b+" in CompressionResponseStream "); + } + if (closed) + throw new IOException("Cannot write to a closed output stream"); + + if (bufferCount >= buffer.length) { + flushToGZip(); + } + + buffer[bufferCount++] = (byte) b; + + } + + + /** + * Write b.length bytes from the specified byte array + * to our output stream. + * + * @param b The byte array to be written + * + * @exception IOException if an input/output error occurs + */ + public void write(byte b[]) throws IOException { + + write(b, 0, b.length); + + } + + + /** + * Write len bytes from the specified byte array, starting + * at the specified offset, to our output stream. + * + * @param b The byte array containing the bytes to be written + * @param off Zero-relative starting offset of the bytes to be written + * @param len The number of bytes to be written + * + * @exception IOException if an input/output error occurs + */ + public void write(byte b[], int off, int len) throws IOException { + + if (debug > 1) { + System.out.println("write, bufferCount = " + bufferCount + " len = " + len + " off = " + off); + } + if (debug > 2) { + System.out.print("write("); + System.out.write(b, off, len); + System.out.println(")"); + } + + if (closed) + throw new IOException("Cannot write to a closed output stream"); + + if (len == 0) + return; + + // Can we write into buffer ? + if (len <= (buffer.length - bufferCount)) { + System.arraycopy(b, off, buffer, bufferCount, len); + bufferCount += len; + return; + } + + // There is not enough space in buffer. Flush it ... + flushToGZip(); + + // ... and try again. Note, that bufferCount = 0 here ! + if (len <= (buffer.length - bufferCount)) { + System.arraycopy(b, off, buffer, bufferCount, len); + bufferCount += len; + return; + } + + // write direct to gzip + writeToGZip(b, off, len); + } + + public void writeToGZip(byte b[], int off, int len) throws IOException { + + if (debug > 1) { + System.out.println("writeToGZip, len = " + len); + } + if (debug > 2) { + System.out.print("writeToGZip("); + System.out.write(b, off, len); + System.out.println(")"); + } + if (gzipstream == null) { + if (debug > 1) { + System.out.println("new GZIPOutputStream"); + } + response.addHeader("Content-Encoding", "gzip"); + gzipstream = new GZIPOutputStream(output); + } + gzipstream.write(b, off, len); + + } + + + // -------------------------------------------------------- Package Methods + + + /** + * Has this response stream been closed? + */ + public boolean closed() { + + return (this.closed); + + } + +} diff --git a/webapps/examples/WEB-INF/classes/compressionFilters/CompressionServletResponseWrapper.java b/webapps/examples/WEB-INF/classes/compressionFilters/CompressionServletResponseWrapper.java new file mode 100644 index 000000000..6dcd8d1f9 --- /dev/null +++ b/webapps/examples/WEB-INF/classes/compressionFilters/CompressionServletResponseWrapper.java @@ -0,0 +1,276 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package compressionFilters; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.util.Locale; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.ServletException; +import javax.servlet.ServletOutputStream; +import javax.servlet.ServletResponse; +import javax.servlet.ServletResponseWrapper; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpServletResponseWrapper; + +/** + * Implementation of HttpServletResponseWrapper that works with + * the CompressionServletResponseStream implementation.. + * + * @author Amy Roh + * @author Dmitri Valdin + * @version $Revision: 267129 $, $Date: 2004-03-18 17:40:35 +0100 (jeu., 18 mars 2004) $ + */ + +public class CompressionServletResponseWrapper extends HttpServletResponseWrapper { + + // ----------------------------------------------------- Constructor + + /** + * Calls the parent constructor which creates a ServletResponse adaptor + * wrapping the given response object. + */ + + public CompressionServletResponseWrapper(HttpServletResponse response) { + super(response); + origResponse = response; + if (debug > 1) { + System.out.println("CompressionServletResponseWrapper constructor gets called"); + } + } + + + // ----------------------------------------------------- Instance Variables + + /** + * Original response + */ + + protected HttpServletResponse origResponse = null; + + /** + * Descriptive information about this Response implementation. + */ + + protected static final String info = "CompressionServletResponseWrapper"; + + /** + * The ServletOutputStream that has been returned by + * getOutputStream(), if any. + */ + + protected ServletOutputStream stream = null; + + + /** + * The PrintWriter that has been returned by + * getWriter(), if any. + */ + + protected PrintWriter writer = null; + + /** + * The threshold number to compress + */ + protected int threshold = 0; + + /** + * Debug level + */ + private int debug = 0; + + /** + * Content type + */ + protected String contentType = null; + + // --------------------------------------------------------- Public Methods + + + /** + * Set content type + */ + public void setContentType(String contentType) { + if (debug > 1) { + System.out.println("setContentType to "+contentType); + } + this.contentType = contentType; + origResponse.setContentType(contentType); + } + + + /** + * Set threshold number + */ + public void setCompressionThreshold(int threshold) { + if (debug > 1) { + System.out.println("setCompressionThreshold to " + threshold); + } + this.threshold = threshold; + } + + + /** + * Set debug level + */ + public void setDebugLevel(int debug) { + this.debug = debug; + } + + + /** + * Create and return a ServletOutputStream to write the content + * associated with this Response. + * + * @exception IOException if an input/output error occurs + */ + public ServletOutputStream createOutputStream() throws IOException { + if (debug > 1) { + System.out.println("createOutputStream gets called"); + } + + CompressionResponseStream stream = new CompressionResponseStream(origResponse); + stream.setDebugLevel(debug); + stream.setBuffer(threshold); + + return stream; + + } + + + /** + * Finish a response. + */ + public void finishResponse() { + try { + if (writer != null) { + writer.close(); + } else { + if (stream != null) + stream.close(); + } + } catch (IOException e) { + } + } + + + // ------------------------------------------------ ServletResponse Methods + + + /** + * Flush the buffer and commit this response. + * + * @exception IOException if an input/output error occurs + */ + public void flushBuffer() throws IOException { + if (debug > 1) { + System.out.println("flush buffer @ CompressionServletResponseWrapper"); + } + ((CompressionResponseStream)stream).flush(); + + } + + /** + * Return the servlet output stream associated with this Response. + * + * @exception IllegalStateException if getWriter has + * already been called for this response + * @exception IOException if an input/output error occurs + */ + public ServletOutputStream getOutputStream() throws IOException { + + if (writer != null) + throw new IllegalStateException("getWriter() has already been called for this response"); + + if (stream == null) + stream = createOutputStream(); + if (debug > 1) { + System.out.println("stream is set to "+stream+" in getOutputStream"); + } + + return (stream); + + } + + /** + * Return the writer associated with this Response. + * + * @exception IllegalStateException if getOutputStream has + * already been called for this response + * @exception IOException if an input/output error occurs + */ + public PrintWriter getWriter() throws IOException { + + if (writer != null) + return (writer); + + if (stream != null) + throw new IllegalStateException("getOutputStream() has already been called for this response"); + + stream = createOutputStream(); + if (debug > 1) { + System.out.println("stream is set to "+stream+" in getWriter"); + } + //String charset = getCharsetFromContentType(contentType); + String charEnc = origResponse.getCharacterEncoding(); + if (debug > 1) { + System.out.println("character encoding is " + charEnc); + } + // HttpServletResponse.getCharacterEncoding() shouldn't return null + // according the spec, so feel free to remove that "if" + if (charEnc != null) { + writer = new PrintWriter(new OutputStreamWriter(stream, charEnc)); + } else { + writer = new PrintWriter(stream); + } + + return (writer); + + } + + + public void setContentLength(int length) { + } + + + /** + * Returns character from content type. This method was taken from tomcat. + * @author rajo + */ + private static String getCharsetFromContentType(String type) { + + if (type == null) { + return null; + } + int semi = type.indexOf(";"); + if (semi == -1) { + return null; + } + String afterSemi = type.substring(semi + 1); + int charsetLocation = afterSemi.indexOf("charset="); + if(charsetLocation == -1) { + return null; + } else { + String afterCharset = afterSemi.substring(charsetLocation + 8); + String encoding = afterCharset.trim(); + return encoding; + } + } + +} diff --git a/webapps/examples/WEB-INF/classes/dates/JspCalendar.java b/webapps/examples/WEB-INF/classes/dates/JspCalendar.java new file mode 100644 index 000000000..b0194755a --- /dev/null +++ b/webapps/examples/WEB-INF/classes/dates/JspCalendar.java @@ -0,0 +1,152 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +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); + } +} + diff --git a/webapps/examples/WEB-INF/classes/error/Smart.java b/webapps/examples/WEB-INF/classes/error/Smart.java new file mode 100644 index 000000000..e5158e7a2 --- /dev/null +++ b/webapps/examples/WEB-INF/classes/error/Smart.java @@ -0,0 +1,34 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + + +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; + } +} diff --git a/webapps/examples/WEB-INF/classes/examples/ExampleTagBase.java b/webapps/examples/WEB-INF/classes/examples/ExampleTagBase.java new file mode 100644 index 000000000..4b64e9581 --- /dev/null +++ b/webapps/examples/WEB-INF/classes/examples/ExampleTagBase.java @@ -0,0 +1,66 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package examples; + +import javax.servlet.jsp.*; +import javax.servlet.jsp.tagext.*; + +public abstract class ExampleTagBase extends BodyTagSupport { + + 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; +} diff --git a/webapps/examples/WEB-INF/classes/examples/FooTag.java b/webapps/examples/WEB-INF/classes/examples/FooTag.java new file mode 100644 index 000000000..e03dc191c --- /dev/null +++ b/webapps/examples/WEB-INF/classes/examples/FooTag.java @@ -0,0 +1,82 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +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 + * + * + */ + +public class FooTag + extends ExampleTagBase +{ + 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 { + i = 0; + 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()); + } + } +} + diff --git a/webapps/examples/WEB-INF/classes/examples/FooTagExtraInfo.java b/webapps/examples/WEB-INF/classes/examples/FooTagExtraInfo.java new file mode 100644 index 000000000..c32c28d1a --- /dev/null +++ b/webapps/examples/WEB-INF/classes/examples/FooTagExtraInfo.java @@ -0,0 +1,32 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +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) + }; + } +} + + diff --git a/webapps/examples/WEB-INF/classes/examples/LogTag.java b/webapps/examples/WEB-INF/classes/examples/LogTag.java new file mode 100644 index 000000000..392a3d587 --- /dev/null +++ b/webapps/examples/WEB-INF/classes/examples/LogTag.java @@ -0,0 +1,60 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +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 +{ + 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()); + } + } +} + + + + diff --git a/webapps/examples/WEB-INF/classes/examples/ShowSource.java b/webapps/examples/WEB-INF/classes/examples/ShowSource.java new file mode 100644 index 000000000..6daf0cff0 --- /dev/null +++ b/webapps/examples/WEB-INF/classes/examples/ShowSource.java @@ -0,0 +1,72 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +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) || + (jspFile.toUpperCase().indexOf("/WEB-INF/") != 0) || + (jspFile.toUpperCase().indexOf("/META-INF/") != 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(""); + out.println("

");
+            for(int ch = in.read(); ch != -1; ch = in.read())
+                if (ch == '<')
+                    out.print("<");
+                else
+                    out.print((char) ch);
+            out.println("
"); + out.println(""); + } catch (IOException ex) { + throw new JspTagException("IOException: "+ex.toString()); + } + return super.doEndTag(); + } +} + + + + diff --git a/webapps/examples/WEB-INF/classes/filters/ExampleFilter.java b/webapps/examples/WEB-INF/classes/filters/ExampleFilter.java new file mode 100644 index 000000000..6981b8bcb --- /dev/null +++ b/webapps/examples/WEB-INF/classes/filters/ExampleFilter.java @@ -0,0 +1,139 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package filters; + + +import java.io.IOException; +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + + +/** + * Example filter that can be attached to either an individual servlet + * or to a URL pattern. This filter performs the following functions: + *
    + *
  • Attaches itself as a request attribute, under the attribute name + * defined by the value of the attribute initialization + * parameter.
  • + *
  • Calculates the number of milliseconds required to perform the + * servlet processing required by this request, including any + * subsequently defined filters, and logs the result to the servlet + * context log for this application. + *
+ * + * @author Craig McClanahan + * @version $Revision: 267129 $ $Date: 2004-03-18 17:40:35 +0100 (jeu., 18 mars 2004) $ + */ + +public final class ExampleFilter implements Filter { + + + // ----------------------------------------------------- Instance Variables + + + /** + * The request attribute name under which we store a reference to ourself. + */ + private String attribute = null; + + + /** + * The filter configuration object we are associated with. If this value + * is null, this filter instance is not currently configured. + */ + private FilterConfig filterConfig = null; + + + // --------------------------------------------------------- Public Methods + + + /** + * Take this filter out of service. + */ + public void destroy() { + + this.attribute = null; + this.filterConfig = null; + + } + + + /** + * Time the processing that is performed by all subsequent filters in the + * current filter stack, including the ultimately invoked servlet. + * + * @param request The servlet request we are processing + * @param result The servlet response we are creating + * @param chain The filter chain we are processing + * + * @exception IOException if an input/output error occurs + * @exception ServletException if a servlet error occurs + */ + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) + throws IOException, ServletException { + + // Store ourselves as a request attribute (if requested) + if (attribute != null) + request.setAttribute(attribute, this); + + // Time and log the subsequent processing + long startTime = System.currentTimeMillis(); + chain.doFilter(request, response); + long stopTime = System.currentTimeMillis(); + filterConfig.getServletContext().log + (this.toString() + ": " + (stopTime - startTime) + + " milliseconds"); + + } + + + /** + * Place this filter into service. + * + * @param filterConfig The filter configuration object + */ + public void init(FilterConfig filterConfig) throws ServletException { + + this.filterConfig = filterConfig; + this.attribute = filterConfig.getInitParameter("attribute"); + + } + + + /** + * Return a String representation of this object. + */ + public String toString() { + + if (filterConfig == null) + return ("InvokerFilter()"); + StringBuffer sb = new StringBuffer("InvokerFilter("); + sb.append(filterConfig); + sb.append(")"); + return (sb.toString()); + + } + + +} + diff --git a/webapps/examples/WEB-INF/classes/filters/RequestDumperFilter.java b/webapps/examples/WEB-INF/classes/filters/RequestDumperFilter.java new file mode 100644 index 000000000..d9d2c409d --- /dev/null +++ b/webapps/examples/WEB-INF/classes/filters/RequestDumperFilter.java @@ -0,0 +1,200 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + + +package filters; + + +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.sql.Timestamp; +import java.util.Enumeration; +import java.util.Locale; +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; + + +/** + * Example filter that dumps interesting state information about a request + * to the associated servlet context log file, before allowing the servlet + * to process the request in the usual way. This can be installed as needed + * to assist in debugging problems. + * + * @author Craig McClanahan + * @version $Revision: 267129 $ $Date: 2004-03-18 17:40:35 +0100 (jeu., 18 mars 2004) $ + */ + +public final class RequestDumperFilter implements Filter { + + + // ----------------------------------------------------- Instance Variables + + + /** + * The filter configuration object we are associated with. If this value + * is null, this filter instance is not currently configured. + */ + private FilterConfig filterConfig = null; + + + // --------------------------------------------------------- Public Methods + + + /** + * Take this filter out of service. + */ + public void destroy() { + + this.filterConfig = null; + + } + + + /** + * Time the processing that is performed by all subsequent filters in the + * current filter stack, including the ultimately invoked servlet. + * + * @param request The servlet request we are processing + * @param result The servlet response we are creating + * @param chain The filter chain we are processing + * + * @exception IOException if an input/output error occurs + * @exception ServletException if a servlet error occurs + */ + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) + throws IOException, ServletException { + + if (filterConfig == null) + return; + + // Render the generic servlet request properties + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + writer.println("Request Received at " + + (new Timestamp(System.currentTimeMillis()))); + writer.println(" characterEncoding=" + request.getCharacterEncoding()); + writer.println(" contentLength=" + request.getContentLength()); + writer.println(" contentType=" + request.getContentType()); + writer.println(" locale=" + request.getLocale()); + writer.print(" locales="); + Enumeration locales = request.getLocales(); + boolean first = true; + while (locales.hasMoreElements()) { + Locale locale = (Locale) locales.nextElement(); + if (first) + first = false; + else + writer.print(", "); + writer.print(locale.toString()); + } + writer.println(); + Enumeration names = request.getParameterNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + writer.print(" parameter=" + name + "="); + String values[] = request.getParameterValues(name); + for (int i = 0; i < values.length; i++) { + if (i > 0) + writer.print(", "); + writer.print(values[i]); + } + writer.println(); + } + writer.println(" protocol=" + request.getProtocol()); + writer.println(" remoteAddr=" + request.getRemoteAddr()); + writer.println(" remoteHost=" + request.getRemoteHost()); + writer.println(" scheme=" + request.getScheme()); + writer.println(" serverName=" + request.getServerName()); + writer.println(" serverPort=" + request.getServerPort()); + writer.println(" isSecure=" + request.isSecure()); + + // Render the HTTP servlet request properties + if (request instanceof HttpServletRequest) { + writer.println("---------------------------------------------"); + HttpServletRequest hrequest = (HttpServletRequest) request; + writer.println(" contextPath=" + hrequest.getContextPath()); + Cookie cookies[] = hrequest.getCookies(); + if (cookies == null) + cookies = new Cookie[0]; + for (int i = 0; i < cookies.length; i++) { + writer.println(" cookie=" + cookies[i].getName() + + "=" + cookies[i].getValue()); + } + names = hrequest.getHeaderNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + String value = hrequest.getHeader(name); + writer.println(" header=" + name + "=" + value); + } + writer.println(" method=" + hrequest.getMethod()); + writer.println(" pathInfo=" + hrequest.getPathInfo()); + writer.println(" queryString=" + hrequest.getQueryString()); + writer.println(" remoteUser=" + hrequest.getRemoteUser()); + writer.println("requestedSessionId=" + + hrequest.getRequestedSessionId()); + writer.println(" requestURI=" + hrequest.getRequestURI()); + writer.println(" servletPath=" + hrequest.getServletPath()); + } + writer.println("============================================="); + + // Log the resulting string + writer.flush(); + filterConfig.getServletContext().log(sw.getBuffer().toString()); + + // Pass control on to the next filter + chain.doFilter(request, response); + + } + + + /** + * Place this filter into service. + * + * @param filterConfig The filter configuration object + */ + public void init(FilterConfig filterConfig) throws ServletException { + + this.filterConfig = filterConfig; + + } + + + /** + * Return a String representation of this object. + */ + public String toString() { + + if (filterConfig == null) + return ("RequestDumperFilter()"); + StringBuffer sb = new StringBuffer("RequestDumperFilter("); + sb.append(filterConfig); + sb.append(")"); + return (sb.toString()); + + } + + +} + diff --git a/webapps/examples/WEB-INF/classes/filters/SetCharacterEncodingFilter.java b/webapps/examples/WEB-INF/classes/filters/SetCharacterEncodingFilter.java new file mode 100644 index 000000000..ef77c7e62 --- /dev/null +++ b/webapps/examples/WEB-INF/classes/filters/SetCharacterEncodingFilter.java @@ -0,0 +1,171 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package filters; + + +import java.io.IOException; +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.UnavailableException; + + +/** + *

Example filter that sets the character encoding to be used in parsing the + * incoming request, either unconditionally or only if the client did not + * specify a character encoding. Configuration of this filter is based on + * the following initialization parameters:

+ *
    + *
  • encoding - The character encoding to be configured + * for this request, either conditionally or unconditionally based on + * the ignore initialization parameter. This parameter + * is required, so there is no default.
  • + *
  • ignore - If set to "true", any character encoding + * specified by the client is ignored, and the value returned by the + * selectEncoding() method is set. If set to "false, + * selectEncoding() is called only if the + * client has not already specified an encoding. By default, this + * parameter is set to "true".
  • + *
+ * + *

Although this filter can be used unchanged, it is also easy to + * subclass it and make the selectEncoding() method more + * intelligent about what encoding to choose, based on characteristics of + * the incoming request (such as the values of the Accept-Language + * and User-Agent headers, or a value stashed in the current + * user's session.

+ * + * @author Craig McClanahan + * @version $Revision: 267129 $ $Date: 2004-03-18 17:40:35 +0100 (jeu., 18 mars 2004) $ + */ + +public class SetCharacterEncodingFilter implements Filter { + + + // ----------------------------------------------------- Instance Variables + + + /** + * The default character encoding to set for requests that pass through + * this filter. + */ + protected String encoding = null; + + + /** + * The filter configuration object we are associated with. If this value + * is null, this filter instance is not currently configured. + */ + protected FilterConfig filterConfig = null; + + + /** + * Should a character encoding specified by the client be ignored? + */ + protected boolean ignore = true; + + + // --------------------------------------------------------- Public Methods + + + /** + * Take this filter out of service. + */ + public void destroy() { + + this.encoding = null; + this.filterConfig = null; + + } + + + /** + * Select and set (if specified) the character encoding to be used to + * interpret request parameters for this request. + * + * @param request The servlet request we are processing + * @param result The servlet response we are creating + * @param chain The filter chain we are processing + * + * @exception IOException if an input/output error occurs + * @exception ServletException if a servlet error occurs + */ + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) + throws IOException, ServletException { + + // Conditionally select and set the character encoding to be used + if (ignore || (request.getCharacterEncoding() == null)) { + String encoding = selectEncoding(request); + if (encoding != null) + request.setCharacterEncoding(encoding); + } + + // Pass control on to the next filter + chain.doFilter(request, response); + + } + + + /** + * Place this filter into service. + * + * @param filterConfig The filter configuration object + */ + public void init(FilterConfig filterConfig) throws ServletException { + + this.filterConfig = filterConfig; + this.encoding = filterConfig.getInitParameter("encoding"); + String value = filterConfig.getInitParameter("ignore"); + if (value == null) + this.ignore = true; + else if (value.equalsIgnoreCase("true")) + this.ignore = true; + else if (value.equalsIgnoreCase("yes")) + this.ignore = true; + else + this.ignore = false; + + } + + + // ------------------------------------------------------ Protected Methods + + + /** + * Select an appropriate character encoding to be used, based on the + * characteristics of the current request and/or filter initialization + * parameters. If no character encoding should be set, return + * null. + *

+ * The default implementation unconditionally returns the value configured + * by the encoding initialization parameter for this + * filter. + * + * @param request The servlet request we are processing + */ + protected String selectEncoding(ServletRequest request) { + + return (this.encoding); + + } + + +} diff --git a/webapps/examples/WEB-INF/classes/jsp2/examples/BookBean.java b/webapps/examples/WEB-INF/classes/jsp2/examples/BookBean.java new file mode 100644 index 000000000..4e2f18d4d --- /dev/null +++ b/webapps/examples/WEB-INF/classes/jsp2/examples/BookBean.java @@ -0,0 +1,43 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + + +package jsp2.examples; + +public class BookBean { + private String title; + private String author; + private String isbn; + + public BookBean( String title, String author, String isbn ) { + this.title = title; + this.author = author; + this.isbn = isbn; + } + + public String getTitle() { + return this.title; + } + + public String getAuthor() { + return this.author; + } + + public String getIsbn() { + return this.isbn; + } + +} diff --git a/webapps/examples/WEB-INF/classes/jsp2/examples/FooBean.java b/webapps/examples/WEB-INF/classes/jsp2/examples/FooBean.java new file mode 100644 index 000000000..c0bd10723 --- /dev/null +++ b/webapps/examples/WEB-INF/classes/jsp2/examples/FooBean.java @@ -0,0 +1,35 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + + +package jsp2.examples; + +public class FooBean { + private String bar; + + public FooBean() { + bar = "Initial value"; + } + + public String getBar() { + return this.bar; + } + + public void setBar(String bar) { + this.bar = bar; + } + +} diff --git a/webapps/examples/WEB-INF/classes/jsp2/examples/el/Functions.java b/webapps/examples/WEB-INF/classes/jsp2/examples/el/Functions.java new file mode 100644 index 000000000..34732e232 --- /dev/null +++ b/webapps/examples/WEB-INF/classes/jsp2/examples/el/Functions.java @@ -0,0 +1,44 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package jsp2.examples.el; + +import java.util.*; + +/** + * Defines the functions for the jsp2 example tag library. + * + *

Each function is defined as a static method.

+ */ +public class Functions { + public static String reverse( String text ) { + return new StringBuffer( text ).reverse().toString(); + } + + public static int numVowels( String text ) { + String vowels = "aeiouAEIOU"; + int result = 0; + for( int i = 0; i < text.length(); i++ ) { + if( vowels.indexOf( text.charAt( i ) ) != -1 ) { + result++; + } + } + return result; + } + + public static String caps( String text ) { + return text.toUpperCase(); + } +} diff --git a/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/EchoAttributesTag.java b/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/EchoAttributesTag.java new file mode 100644 index 000000000..8c55db9ad --- /dev/null +++ b/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/EchoAttributesTag.java @@ -0,0 +1,54 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + + +package jsp2.examples.simpletag; + +import javax.servlet.jsp.JspException; +import javax.servlet.jsp.JspWriter; +import javax.servlet.jsp.tagext.SimpleTagSupport; +import javax.servlet.jsp.tagext.DynamicAttributes; +import java.util.ArrayList; +import java.util.Iterator; +import java.io.IOException; + +/** + * SimpleTag handler that echoes all its attributes + */ +public class EchoAttributesTag + extends SimpleTagSupport + implements DynamicAttributes +{ + private ArrayList keys = new ArrayList(); + private ArrayList values = new ArrayList(); + + public void doTag() throws JspException, IOException { + JspWriter out = getJspContext().getOut(); + for( int i = 0; i < keys.size(); i++ ) { + String key = (String)keys.get( i ); + Object value = values.get( i ); + out.println( "
  • " + key + " = " + value + "
  • " ); + } + } + + public void setDynamicAttribute( String uri, String localName, + Object value ) + throws JspException + { + keys.add( localName ); + values.add( value ); + } +} diff --git a/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/FindBookSimpleTag.java b/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/FindBookSimpleTag.java new file mode 100644 index 000000000..52a5e15e7 --- /dev/null +++ b/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/FindBookSimpleTag.java @@ -0,0 +1,44 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + + +package jsp2.examples.simpletag; + +import javax.servlet.jsp.JspException; +import javax.servlet.jsp.tagext.SimpleTagSupport; +import java.util.HashMap; +import jsp2.examples.BookBean; + +/** + * SimpleTag handler that pretends to search for a book, and stores + * the result in a scoped variable. + */ +public class FindBookSimpleTag extends SimpleTagSupport { + private String var; + + private static final String BOOK_TITLE = "The Lord of the Rings"; + private static final String BOOK_AUTHOR = "J. R. R. Tolkein"; + private static final String BOOK_ISBN = "0618002251"; + + public void doTag() throws JspException { + BookBean book = new BookBean( BOOK_TITLE, BOOK_AUTHOR, BOOK_ISBN ); + getJspContext().setAttribute( this.var, book ); + } + + public void setVar( String var ) { + this.var = var; + } +} diff --git a/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/HelloWorldSimpleTag.java b/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/HelloWorldSimpleTag.java new file mode 100644 index 000000000..7a4196c66 --- /dev/null +++ b/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/HelloWorldSimpleTag.java @@ -0,0 +1,31 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + + +package jsp2.examples.simpletag; + +import javax.servlet.jsp.JspException; +import javax.servlet.jsp.tagext.SimpleTagSupport; +import java.io.IOException; + +/** + * SimpleTag handler that prints "Hello, world!" + */ +public class HelloWorldSimpleTag extends SimpleTagSupport { + public void doTag() throws JspException, IOException { + getJspContext().getOut().write( "Hello, world!" ); + } +} diff --git a/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/RepeatSimpleTag.java b/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/RepeatSimpleTag.java new file mode 100644 index 000000000..0f4b1e524 --- /dev/null +++ b/webapps/examples/WEB-INF/classes/jsp2/examples/simpletag/RepeatSimpleTag.java @@ -0,0 +1,42 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + + +package jsp2.examples.simpletag; + +import javax.servlet.jsp.JspException; +import javax.servlet.jsp.tagext.SimpleTagSupport; +import java.util.HashMap; +import java.io.IOException; + +/** + * SimpleTag handler that accepts a num attribute and + * invokes its body 'num' times. + */ +public class RepeatSimpleTag extends SimpleTagSupport { + private int num; + + public void doTag() throws JspException, IOException { + for (int i=0; i
    " + this.label + + "
    " ); + } + + public void setColor( String color ) { + this.color = color; + } + + public void setLabel( String label ) { + this.label = label; + } +} diff --git a/webapps/examples/WEB-INF/classes/listeners/ContextListener.java b/webapps/examples/WEB-INF/classes/listeners/ContextListener.java new file mode 100644 index 000000000..6f5636380 --- /dev/null +++ b/webapps/examples/WEB-INF/classes/listeners/ContextListener.java @@ -0,0 +1,155 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package listeners; + + +import javax.servlet.ServletContext; +import javax.servlet.ServletContextAttributeEvent; +import javax.servlet.ServletContextAttributeListener; +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + + +/** + * Example listener for context-related application events, which were + * introduced in the 2.3 version of the Servlet API. This listener + * merely documents the occurrence of such events in the application log + * associated with our servlet context. + * + * @author Craig R. McClanahan + * @version $Revision: 267129 $ $Date: 2004-03-18 17:40:35 +0100 (jeu., 18 mars 2004) $ + */ + +public final class ContextListener + implements ServletContextAttributeListener, ServletContextListener { + + + // ----------------------------------------------------- Instance Variables + + + /** + * The servlet context with which we are associated. + */ + private ServletContext context = null; + + + // --------------------------------------------------------- Public Methods + + + /** + * Record the fact that a servlet context attribute was added. + * + * @param event The servlet context attribute event + */ + public void attributeAdded(ServletContextAttributeEvent event) { + + log("attributeAdded('" + event.getName() + "', '" + + event.getValue() + "')"); + + } + + + /** + * Record the fact that a servlet context attribute was removed. + * + * @param event The servlet context attribute event + */ + public void attributeRemoved(ServletContextAttributeEvent event) { + + log("attributeRemoved('" + event.getName() + "', '" + + event.getValue() + "')"); + + } + + + /** + * Record the fact that a servlet context attribute was replaced. + * + * @param event The servlet context attribute event + */ + public void attributeReplaced(ServletContextAttributeEvent event) { + + log("attributeReplaced('" + event.getName() + "', '" + + event.getValue() + "')"); + + } + + + /** + * Record the fact that this web application has been destroyed. + * + * @param event The servlet context event + */ + public void contextDestroyed(ServletContextEvent event) { + + log("contextDestroyed()"); + this.context = null; + + } + + + /** + * Record the fact that this web application has been initialized. + * + * @param event The servlet context event + */ + public void contextInitialized(ServletContextEvent event) { + + this.context = event.getServletContext(); + log("contextInitialized()"); + + } + + + // -------------------------------------------------------- Private Methods + + + /** + * Log a message to the servlet context application log. + * + * @param message Message to be logged + */ + private void log(String message) { + + if (context != null) + context.log("ContextListener: " + message); + else + System.out.println("ContextListener: " + message); + + } + + + /** + * Log a message and associated exception to the servlet context + * application log. + * + * @param message Message to be logged + * @param throwable Exception to be logged + */ + private void log(String message, Throwable throwable) { + + if (context != null) + context.log("ContextListener: " + message, throwable); + else { + System.out.println("ContextListener: " + message); + throwable.printStackTrace(System.out); + } + + } + + +} diff --git a/webapps/examples/WEB-INF/classes/listeners/SessionListener.java b/webapps/examples/WEB-INF/classes/listeners/SessionListener.java new file mode 100644 index 000000000..540547dcf --- /dev/null +++ b/webapps/examples/WEB-INF/classes/listeners/SessionListener.java @@ -0,0 +1,182 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package listeners; + + +import javax.servlet.ServletContext; +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; +import javax.servlet.http.HttpSessionAttributeListener; +import javax.servlet.http.HttpSessionBindingEvent; +import javax.servlet.http.HttpSessionEvent; +import javax.servlet.http.HttpSessionListener; + + +/** + * Example listener for context-related application events, which were + * introduced in the 2.3 version of the Servlet API. This listener + * merely documents the occurrence of such events in the application log + * associated with our servlet context. + * + * @author Craig R. McClanahan + * @version $Revision: 267129 $ $Date: 2004-03-18 17:40:35 +0100 (jeu., 18 mars 2004) $ + */ + +public final class SessionListener + implements ServletContextListener, + HttpSessionAttributeListener, HttpSessionListener { + + + // ----------------------------------------------------- Instance Variables + + + /** + * The servlet context with which we are associated. + */ + private ServletContext context = null; + + + // --------------------------------------------------------- Public Methods + + + /** + * Record the fact that a servlet context attribute was added. + * + * @param event The session attribute event + */ + public void attributeAdded(HttpSessionBindingEvent event) { + + log("attributeAdded('" + event.getSession().getId() + "', '" + + event.getName() + "', '" + event.getValue() + "')"); + + } + + + /** + * Record the fact that a servlet context attribute was removed. + * + * @param event The session attribute event + */ + public void attributeRemoved(HttpSessionBindingEvent event) { + + log("attributeRemoved('" + event.getSession().getId() + "', '" + + event.getName() + "', '" + event.getValue() + "')"); + + } + + + /** + * Record the fact that a servlet context attribute was replaced. + * + * @param event The session attribute event + */ + public void attributeReplaced(HttpSessionBindingEvent event) { + + log("attributeReplaced('" + event.getSession().getId() + "', '" + + event.getName() + "', '" + event.getValue() + "')"); + + } + + + /** + * Record the fact that this web application has been destroyed. + * + * @param event The servlet context event + */ + public void contextDestroyed(ServletContextEvent event) { + + log("contextDestroyed()"); + this.context = null; + + } + + + /** + * Record the fact that this web application has been initialized. + * + * @param event The servlet context event + */ + public void contextInitialized(ServletContextEvent event) { + + this.context = event.getServletContext(); + log("contextInitialized()"); + + } + + + /** + * Record the fact that a session has been created. + * + * @param event The session event + */ + public void sessionCreated(HttpSessionEvent event) { + + log("sessionCreated('" + event.getSession().getId() + "')"); + + } + + + /** + * Record the fact that a session has been destroyed. + * + * @param event The session event + */ + public void sessionDestroyed(HttpSessionEvent event) { + + log("sessionDestroyed('" + event.getSession().getId() + "')"); + + } + + + // -------------------------------------------------------- Private Methods + + + /** + * Log a message to the servlet context application log. + * + * @param message Message to be logged + */ + private void log(String message) { + + if (context != null) + context.log("SessionListener: " + message); + else + System.out.println("SessionListener: " + message); + + } + + + /** + * Log a message and associated exception to the servlet context + * application log. + * + * @param message Message to be logged + * @param throwable Exception to be logged + */ + private void log(String message, Throwable throwable) { + + if (context != null) + context.log("SessionListener: " + message, throwable); + else { + System.out.println("SessionListener: " + message); + throwable.printStackTrace(System.out); + } + + } + + +} diff --git a/webapps/examples/WEB-INF/classes/num/NumberGuessBean.java b/webapps/examples/WEB-INF/classes/num/NumberGuessBean.java new file mode 100644 index 000000000..b5afeaba3 --- /dev/null +++ b/webapps/examples/WEB-INF/classes/num/NumberGuessBean.java @@ -0,0 +1,78 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* + * 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; + } +} diff --git a/webapps/examples/WEB-INF/classes/servletToJsp.java b/webapps/examples/WEB-INF/classes/servletToJsp.java new file mode 100644 index 000000000..38a2c726b --- /dev/null +++ b/webapps/examples/WEB-INF/classes/servletToJsp.java @@ -0,0 +1,32 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +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("/jsptoserv/hello.jsp").forward(request, response); + } catch (Exception ex) { + ex.printStackTrace (); + } + } +} diff --git a/webapps/examples/WEB-INF/classes/sessions/DummyCart.java b/webapps/examples/WEB-INF/classes/sessions/DummyCart.java new file mode 100644 index 000000000..17ccd80b8 --- /dev/null +++ b/webapps/examples/WEB-INF/classes/sessions/DummyCart.java @@ -0,0 +1,69 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +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; + } +} diff --git a/webapps/examples/WEB-INF/classes/util/HTMLFilter.java b/webapps/examples/WEB-INF/classes/util/HTMLFilter.java new file mode 100644 index 000000000..3b6b9276c --- /dev/null +++ b/webapps/examples/WEB-INF/classes/util/HTMLFilter.java @@ -0,0 +1,68 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package util; + +/** + * HTML filter utility. + * + * @author Craig R. McClanahan + * @author Tim Tye + * @version $Revision: 267129 $ $Date: 2004-03-18 17:40:35 +0100 (jeu., 18 mars 2004) $ + */ + +public final class HTMLFilter { + + + /** + * Filter the specified message string for characters that are sensitive + * in HTML. This avoids potential attacks caused by including JavaScript + * codes in the request URL that is often reported in error messages. + * + * @param message The message string to be filtered + */ + public static String filter(String message) { + + if (message == null) + return (null); + + char content[] = new char[message.length()]; + message.getChars(0, message.length(), content, 0); + StringBuffer result = new StringBuffer(content.length + 50); + for (int i = 0; i < content.length; i++) { + switch (content[i]) { + case '<': + result.append("<"); + break; + case '>': + result.append(">"); + break; + case '&': + result.append("&"); + break; + case '"': + result.append("""); + break; + default: + result.append(content[i]); + } + } + return (result.toString()); + + } + + +} + diff --git a/webapps/examples/WEB-INF/classes/validators/DebugValidator.java b/webapps/examples/WEB-INF/classes/validators/DebugValidator.java new file mode 100644 index 000000000..bb55026c8 --- /dev/null +++ b/webapps/examples/WEB-INF/classes/validators/DebugValidator.java @@ -0,0 +1,83 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + + +package validators; + + +import java.io.InputStream; +import java.io.IOException; +import javax.servlet.jsp.tagext.PageData; +import javax.servlet.jsp.tagext.TagLibraryValidator; +import javax.servlet.jsp.tagext.ValidationMessage; + + +/** + * Example tag library validator that simply dumps the XML version of each + * page to standard output (which will typically be sent to the file + * $CATALINA_HOME/logs/catalina.out). To utilize it, simply + * include a taglib directive for this tag library at the top + * of your JSP page. + * + * @author Craig McClanahan + * @version $Revision: 267129 $ $Date: 2004-03-18 17:40:35 +0100 (jeu., 18 mars 2004) $ + */ + +public class DebugValidator extends TagLibraryValidator { + + + // ----------------------------------------------------- Instance Variables + + + // --------------------------------------------------------- Public Methods + + + /** + * Validate a JSP page. This will get invoked once per directive in the + * JSP page. This method will return null if the page is + * valid; otherwise the method should return an array of + * ValidationMessage objects. An array of length zero is + * also interpreted as no errors. + * + * @param prefix The value of the prefix argument in this directive + * @param uri The value of the URI argument in this directive + * @param page The page data for this page + */ + public ValidationMessage[] validate(String prefix, String uri, + PageData page) { + + System.out.println("---------- Prefix=" + prefix + " URI=" + uri + + "----------"); + + InputStream is = page.getInputStream(); + while (true) { + try { + int ch = is.read(); + if (ch < 0) + break; + System.out.print((char) ch); + } catch (IOException e) { + break; + } + } + System.out.println(); + System.out.println("-----------------------------------------------"); + return (null); + + } + + +} diff --git a/webapps/examples/WEB-INF/jsp/applet/Clock2.java b/webapps/examples/WEB-INF/jsp/applet/Clock2.java new file mode 100644 index 000000000..edbf29287 --- /dev/null +++ b/webapps/examples/WEB-INF/jsp/applet/Clock2.java @@ -0,0 +1,211 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +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; + } +} diff --git a/webapps/examples/WEB-INF/jsp/debug-taglib.tld b/webapps/examples/WEB-INF/jsp/debug-taglib.tld new file mode 100644 index 000000000..dbf39b058 --- /dev/null +++ b/webapps/examples/WEB-INF/jsp/debug-taglib.tld @@ -0,0 +1,53 @@ + + + + + + + + 1.0 + 1.2 + debug + http://jakarta.apache.org/tomcat/debug-taglib + + This tag library defines no tags. Instead, its purpose is encapsulated + in the TagLibraryValidator implementation that simply outputs the XML + version of a JSP page to standard output, whenever this tag library is + referenced in a "taglib" directive in a JSP page. + + + validators.DebugValidator + + + + + log + examples.LogTag + TAGDEPENDENT + + Perform a server side action; Log the message. + + + toBrowser + false + + + + + diff --git a/webapps/examples/WEB-INF/jsp/example-taglib.tld b/webapps/examples/WEB-INF/jsp/example-taglib.tld new file mode 100644 index 000000000..5c0e30bda --- /dev/null +++ b/webapps/examples/WEB-INF/jsp/example-taglib.tld @@ -0,0 +1,82 @@ + + + + + + + 1.0 + 1.2 + simple + http://jakarta.apache.org/tomcat/example-taglib + + A simple tab library for the examples + + + + ShowSource + examples.ShowSource + Display JSP sources + + jspFile + true + true + + + + + + + foo + examples.FooTag + examples.FooTagExtraInfo + JSP + + Perform a server side action; uses 3 mandatory attributes + + + + att1 + true + + + att2 + true + + + att3 + true + + + + + + + log + examples.LogTag + TAGDEPENDENT + + Perform a server side action; Log the message. + + + toBrowser + false + + + + diff --git a/webapps/examples/WEB-INF/jsp2/jsp2-example-taglib.tld b/webapps/examples/WEB-INF/jsp2/jsp2-example-taglib.tld new file mode 100644 index 000000000..c22cd9e7e --- /dev/null +++ b/webapps/examples/WEB-INF/jsp2/jsp2-example-taglib.tld @@ -0,0 +1,123 @@ + + + + + A tag library exercising SimpleTag handlers. + 1.0 + SimpleTagLibrary + /SimpleTagLibrary + + Outputs Hello, World + helloWorld + jsp2.examples.simpletag.HelloWorldSimpleTag + empty + + + Repeats the body of the tag 'num' times + repeat + jsp2.examples.simpletag.RepeatSimpleTag + scriptless + + Current invocation count (1 to num) + count + + + num + true + true + + + + Populates the page context with a BookBean + findBook + jsp2.examples.simpletag.FindBookSimpleTag + empty + + var + true + true + + + + + Takes 3 fragments and invokes them in a random order + + shuffle + jsp2.examples.simpletag.ShuffleSimpleTag + empty + + fragment1 + true + true + + + fragment2 + true + true + + + fragment3 + true + true + + + + Outputs a colored tile + tile + jsp2.examples.simpletag.TileSimpleTag + empty + + color + true + + + label + true + + + + + Tag that echoes all its attributes and body content + + echoAttributes + jsp2.examples.simpletag.EchoAttributesTag + empty + true + + + Reverses the characters in the given String + reverse + jsp2.examples.el.Functions + java.lang.String reverse( java.lang.String ) + + + Counts the number of vowels (a,e,i,o,u) in the given String + countVowels + jsp2.examples.el.Functions + java.lang.String numVowels( java.lang.String ) + + + Converts the string to all caps + caps + jsp2.examples.el.Functions + java.lang.String caps( java.lang.String ) + + + diff --git a/webapps/examples/WEB-INF/lib/jstl.jar b/webapps/examples/WEB-INF/lib/jstl.jar new file mode 100644 index 000000000..6b4135825 Binary files /dev/null and b/webapps/examples/WEB-INF/lib/jstl.jar differ diff --git a/webapps/examples/WEB-INF/lib/standard.jar b/webapps/examples/WEB-INF/lib/standard.jar new file mode 100644 index 000000000..258daaece Binary files /dev/null and b/webapps/examples/WEB-INF/lib/standard.jar differ diff --git a/webapps/examples/WEB-INF/tags/displayProducts.tag b/webapps/examples/WEB-INF/tags/displayProducts.tag new file mode 100644 index 000000000..9a29d33bc --- /dev/null +++ b/webapps/examples/WEB-INF/tags/displayProducts.tag @@ -0,0 +1,54 @@ + +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ attribute name="normalPrice" fragment="true" %> +<%@ attribute name="onSale" fragment="true" %> +<%@ variable name-given="name" %> +<%@ variable name-given="price" %> +<%@ variable name-given="origPrice" %> +<%@ variable name-given="salePrice" %> + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + +
    diff --git a/webapps/examples/WEB-INF/tags/helloWorld.tag b/webapps/examples/WEB-INF/tags/helloWorld.tag new file mode 100644 index 000000000..6f02e6e69 --- /dev/null +++ b/webapps/examples/WEB-INF/tags/helloWorld.tag @@ -0,0 +1,16 @@ + +Hello, world! diff --git a/webapps/examples/WEB-INF/tags/panel.tag b/webapps/examples/WEB-INF/tags/panel.tag new file mode 100644 index 000000000..446b1ad13 --- /dev/null +++ b/webapps/examples/WEB-INF/tags/panel.tag @@ -0,0 +1,28 @@ + +<%@ attribute name="color" %> +<%@ attribute name="bgcolor" %> +<%@ attribute name="title" %> + + + + + + + +
    ${title}
    + +
    diff --git a/webapps/examples/WEB-INF/tags/xhtmlbasic.tag b/webapps/examples/WEB-INF/tags/xhtmlbasic.tag new file mode 100644 index 000000000..a910ad4ce --- /dev/null +++ b/webapps/examples/WEB-INF/tags/xhtmlbasic.tag @@ -0,0 +1,20 @@ + + + + + diff --git a/webapps/examples/WEB-INF/web.xml b/webapps/examples/WEB-INF/web.xml new file mode 100644 index 000000000..77e4262cc --- /dev/null +++ b/webapps/examples/WEB-INF/web.xml @@ -0,0 +1,306 @@ + + + + + + + Servlet and JSP Examples. + + Servlet and JSP Examples + + + + + Servlet Mapped Filter + filters.ExampleFilter + + attribute + filters.ExampleFilter.SERVLET_MAPPED + + + + Path Mapped Filter + filters.ExampleFilter + + attribute + filters.ExampleFilter.PATH_MAPPED + + + + Request Dumper Filter + filters.RequestDumperFilter + + + + + Set Character Encoding + filters.SetCharacterEncodingFilter + + encoding + EUC_JP + + + + + Compression Filter + compressionFilters.CompressionFilter + + + compressionThreshold + 10 + + + debug + 0 + + + + + + Servlet Mapped Filter + invoker + + + Path Mapped Filter + /servlet/* + + + + + + + + + + + + listeners.ContextListener + + + listeners.SessionListener + + + + + + servletToJsp + servletToJsp + + + ChatServlet + chat.ChatServlet + + + CompressionFilterTestServlet + compressionFilters.CompressionFilterTestServlet + + + HelloWorldExample + HelloWorldExample + + + RequestInfoExample + RequestInfoExample + + + RequestHeaderExample + RequestHeaderExample + + + RequestParamExample + RequestParamExample + + + CookieExample + CookieExample + + + SessionExample + SessionExample + + + + ChatServlet + /jsp/chat + + + CompressionFilterTestServlet + /CompressionTest + + + HelloWorldExample + /servlet/HelloWorldExample + + + RequestInfoExample + /servlet/RequestInfoExample/* + + + RequestHeaderExample + /servlet/RequestHeaderExample + + + RequestParamExample + /servlet/RequestParamExample + + + CookieExample + /servlet/CookieExample + + + SessionExample + /servlet/SessionExample + + + servletToJsp + /servletToJsp + + + + + + http://jakarta.apache.org/tomcat/debug-taglib + + + /WEB-INF/jsp/debug-taglib.tld + + + + + + http://jakarta.apache.org/tomcat/examples-taglib + + + /WEB-INF/jsp/example-taglib.tld + + + + + + http://jakarta.apache.org/tomcat/jsp2-example-taglib + + + /WEB-INF/jsp2/jsp2-example-taglib.tld + + + + + + Special property group for JSP Configuration JSP example. + + JSPConfiguration + /jsp2/misc/config.jsp + true + ISO-8859-1 + true + /jsp2/misc/prelude.jspf + /jsp2/misc/coda.jspf + + + + + Example Security Constraint + + Protected Area + + /security/protected/* + + DELETE + GET + POST + PUT + + + + tomcat + role1 + + + + + + FORM + Example Form-Based Authentication Area + + /jsp/security/protected/login.jsp + /jsp/security/protected/error.jsp + + + + + + role1 + + + tomcat + + + + + + minExemptions + java.lang.Integer + 1 + + + foo/name1 + java.lang.String + value1 + + + foo/bar/name2 + java.lang.Boolean + true + + + name3 + java.lang.Integer + 1 + + + foo/name4 + java.lang.Integer + 10 + + + diff --git a/webapps/examples/jsp/cal/cal1.jsp b/webapps/examples/jsp/cal/cal1.jsp new file mode 100644 index 000000000..b3a766d60 --- /dev/null +++ b/webapps/examples/jsp/cal/cal1.jsp @@ -0,0 +1,94 @@ + + + + Calendar: A JSP APPLICATION + + + + + +<%@ page language="java" import="cal.*" %> + + +<% + table.processRequest(request); + if (table.getProcessError() == false) { +%> + + +
    + + + + +
    prev + Calendar:<%= table.getDate() %> next +
    + + + + + + + + +<% + for(int i=0; i + + + + +<% + } +%> + +
    Time Appointment
    + > + <%= entr.getHour() %> + > + <% out.print(util.HTMLFilter.filter(entr.getDescription())); %> +
    +
    + + + + + + +
    <% out.print(util.HTMLFilter.filter(table.getName())); %> : + <% out.print(util.HTMLFilter.filter(table.getEmail())); %>
    +
    + +<% + } else { +%> + + You must enter your name and email address correctly. + +<% + } +%> + + + + + + + + diff --git a/webapps/examples/jsp/cal/cal2.jsp b/webapps/examples/jsp/cal/cal2.jsp new file mode 100644 index 000000000..f3a93eb51 --- /dev/null +++ b/webapps/examples/jsp/cal/cal2.jsp @@ -0,0 +1,44 @@ + + + + + Calendar: A JSP APPLICATION + + + + + + +<% + String time = request.getParameter ("time"); +%> + + Please add the following event: +

    Date <%= table.getDate() %> +
    Time <%= util.HTMLFilter.filter(time) %>

    +
    +
    +
    +
    +
    +

    Description of the event

    +
    +
    + + + + diff --git a/webapps/examples/jsp/cal/calendar.html b/webapps/examples/jsp/cal/calendar.html new file mode 100644 index 000000000..8b1a74cb4 --- /dev/null +++ b/webapps/examples/jsp/cal/calendar.html @@ -0,0 +1,42 @@ + + + + +Untitled Document + + + + +

    + +

    Source Code for Calendar Example.
    +

    cal1.jsp +

    +

    cal2.jsp +

    + +
    +

    Beans. +

    TableBean +

    +

    Entries +

    +

    Entry +

    + + + diff --git a/webapps/examples/jsp/cal/login.html b/webapps/examples/jsp/cal/login.html new file mode 100644 index 000000000..cb8ba4241 --- /dev/null +++ b/webapps/examples/jsp/cal/login.html @@ -0,0 +1,46 @@ + + + + + Login page for the calendar. + + + +
    + + Please Enter the following information: + +
    +
    + + Name + +
    + Email + +
    + + +
    +
    + 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. + +
    + + diff --git a/webapps/examples/jsp/chat/chat.jsp b/webapps/examples/jsp/chat/chat.jsp new file mode 100644 index 000000000..cc53bba49 --- /dev/null +++ b/webapps/examples/jsp/chat/chat.jsp @@ -0,0 +1,32 @@ + + + + + JSP Chat + + + + + + + + + + + + + diff --git a/webapps/examples/jsp/chat/login.jsp b/webapps/examples/jsp/chat/login.jsp new file mode 100644 index 000000000..492a25176 --- /dev/null +++ b/webapps/examples/jsp/chat/login.jsp @@ -0,0 +1,30 @@ + + + + + JSP Chat + + + + +
    + +Nickname: +
    + + + diff --git a/webapps/examples/jsp/chat/post.jsp b/webapps/examples/jsp/chat/post.jsp new file mode 100644 index 000000000..65b40c136 --- /dev/null +++ b/webapps/examples/jsp/chat/post.jsp @@ -0,0 +1,35 @@ + + + + + JSP Chat + + + + +
    + +Message: +
    + +
    +
    + +Click to open chat window + + + diff --git a/webapps/examples/jsp/checkbox/CheckTest.html b/webapps/examples/jsp/checkbox/CheckTest.html new file mode 100644 index 000000000..b26c367ad --- /dev/null +++ b/webapps/examples/jsp/checkbox/CheckTest.html @@ -0,0 +1,55 @@ + + + + + +checkbox.CheckTest Bean Properties + + +

    +checkbox.CheckTest Bean Properties +

    +
    +
    +
    public class CheckTest
    extends Object
    + +

    +


    + +

    + + + + + + + + + +
    +Properties Summary
    + +String +CheckTest:fruit +
    +
    + +Multi +
    +


    + + diff --git a/webapps/examples/jsp/checkbox/check.html b/webapps/examples/jsp/checkbox/check.html new file mode 100644 index 000000000..dabc610d4 --- /dev/null +++ b/webapps/examples/jsp/checkbox/check.html @@ -0,0 +1,37 @@ + + + + + + +
    +
    + +Check all Favorite fruits:
    + + Apples
    + Grapes
    + Oranges
    + Melons
    + + +
    + +
    +
    + + diff --git a/webapps/examples/jsp/checkbox/checkresult.jsp b/webapps/examples/jsp/checkbox/checkresult.jsp new file mode 100644 index 000000000..fb188bb22 --- /dev/null +++ b/webapps/examples/jsp/checkbox/checkresult.jsp @@ -0,0 +1,63 @@ + + + + + +<%! String[] fruits; %> + + + +
    +The checked fruits (got using request) are:
    +<% + fruits = request.getParameterValues("fruit"); +%> +
      +<% + if (fruits != null) { + for (int i = 0; i < fruits.length; i++) { +%> +
    • +<% + out.println (util.HTMLFilter.filter(fruits[i])); + } + } else out.println ("none selected"); +%> +
    +
    +
    + +The checked fruits (got using beans) are
    + +<% + fruits = foo.getFruit(); +%> +
      +<% + if (!fruits[0].equals("1")) { + for (int i = 0; i < fruits.length; i++) { +%> +
    • +<% + out.println (util.HTMLFilter.filter(fruits[i])); + } + } else out.println ("none selected"); +%> +
    +
    + + diff --git a/webapps/examples/jsp/checkbox/cresult.html b/webapps/examples/jsp/checkbox/cresult.html new file mode 100644 index 000000000..1668e5be7 --- /dev/null +++ b/webapps/examples/jsp/checkbox/cresult.html @@ -0,0 +1,33 @@ + + + + +Untitled Document + + + + +

    + +

    Source Code for Checkbox Example +

    + +

    Property Sheet for CheckTest +

    + + + diff --git a/webapps/examples/jsp/colors/ColorGameBean.html b/webapps/examples/jsp/colors/ColorGameBean.html new file mode 100644 index 000000000..11a33f172 --- /dev/null +++ b/webapps/examples/jsp/colors/ColorGameBean.html @@ -0,0 +1,115 @@ + + + + + +colors.ColorGameBean Bean Properties + + +

    +colors.ColorGameBean Bean Properties +

    +
    +
    +
    public class ColorGameBean
    extends Object
    + +

    +


    + +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +Properties Summary
    + +String +ColorGameBean:color2 +
    +
    + +Single +
    + +String +ColorGameBean:color1 +
    +
    + +Single +
    + +int +ColorGameBean:attempts +
    +
    + +Single +
    + +boolean +ColorGameBean:hint +
    +
    + +Single +
    + +boolean +ColorGameBean:success +
    +
    + +Single +
    + +boolean +ColorGameBean:hintTaken +
    +
    + +Single +
    +


    + + diff --git a/webapps/examples/jsp/colors/clr.html b/webapps/examples/jsp/colors/clr.html new file mode 100644 index 000000000..69713e12a --- /dev/null +++ b/webapps/examples/jsp/colors/clr.html @@ -0,0 +1,33 @@ + + + + +Untitled Document + + + + +

    + +

    Source Code for Color Example +

    + +

    Property Sheet for ColorGameBean +

    + + + diff --git a/webapps/examples/jsp/colors/colors.html b/webapps/examples/jsp/colors/colors.html new file mode 100644 index 000000000..bf061fe99 --- /dev/null +++ b/webapps/examples/jsp/colors/colors.html @@ -0,0 +1,46 @@ + + + + + + +
    +This web page is an example using JSP and BEANs. +

    +Guess my favorite two colors + +

    If you fail to guess both of them - you get yellow on red. + +

    If you guess one of them right, either your foreground or + your background will change to the color that was guessed right. + +

    Guess them both right and your browser foreground/background + will change to my two favorite colors to display this page. + +


    +
    +Color #1: +
    +Color #2: +

    + + +

    + +
    + + diff --git a/webapps/examples/jsp/colors/colrs.jsp b/webapps/examples/jsp/colors/colrs.jsp new file mode 100644 index 000000000..8bb7c600d --- /dev/null +++ b/webapps/examples/jsp/colors/colrs.jsp @@ -0,0 +1,69 @@ + + + + + + +<% + cb.processRequest(request); +%> + +> +> +

    + +<% if (cb.getHint()==true) { %> + +

    Hint #1: Vampires prey at night! +

    Hint #2: Nancy without the n. + +<% } %> + +<% if (cb.getSuccess()==true) { %> + +

    CONGRATULATIONS!! + <% if (cb.getHintTaken()==true) { %> + +

    ( although I know you cheated and peeked into the hints) + + <% } %> + +<% } %> + +

    Total attempts so far: <%= cb.getAttempts() %> +

    + +

    + +

    + +Color #1: + +
    + +Color #2: + +

    + + + + +

    + +
    + + diff --git a/webapps/examples/jsp/dates/date.html b/webapps/examples/jsp/dates/date.html new file mode 100644 index 000000000..e8081caf6 --- /dev/null +++ b/webapps/examples/jsp/dates/date.html @@ -0,0 +1,30 @@ + + + + +Untitled Document + + + + +

    + +

    Source Code for Date Example +

    + + + diff --git a/webapps/examples/jsp/dates/date.jsp b/webapps/examples/jsp/dates/date.jsp new file mode 100644 index 000000000..7f3c3b403 --- /dev/null +++ b/webapps/examples/jsp/dates/date.jsp @@ -0,0 +1,40 @@ + + + +<%@ page session="false"%> + + + + + +
      +
    • Day of month: is +
    • Year: is +
    • Month: is +
    • Time: is +
    • Date: is +
    • Day: is +
    • Day Of Year: is +
    • Week Of Year: is +
    • era: is +
    • DST Offset: is +
    • Zone Offset: is +
    +
    + + + diff --git a/webapps/examples/jsp/error/er.html b/webapps/examples/jsp/error/er.html new file mode 100644 index 000000000..1bea6ee68 --- /dev/null +++ b/webapps/examples/jsp/error/er.html @@ -0,0 +1,30 @@ + + + + +Untitled Document + + + + +

    + +

    Source Code for Error Example +

    + + + diff --git a/webapps/examples/jsp/error/err.jsp b/webapps/examples/jsp/error/err.jsp new file mode 100644 index 000000000..3076380c4 --- /dev/null +++ b/webapps/examples/jsp/error/err.jsp @@ -0,0 +1,43 @@ + + + + + <%@ page errorPage="errorpge.jsp" %> + + <% + String name = null; + + if (request.getParameter("name") == null) { + %> + <%@ include file="/error/error.html" %> + <% + } else { + foo.setName(request.getParameter("name")); + if (foo.getName().equalsIgnoreCase("integra")) + name = "acura"; + if (name.equalsIgnoreCase("acura")) { + %> + +

    Yes!!! Acura is my favorite car. + + <% + } + } + %> + + + diff --git a/webapps/examples/jsp/error/error.html b/webapps/examples/jsp/error/error.html new file mode 100644 index 000000000..748718820 --- /dev/null +++ b/webapps/examples/jsp/error/error.html @@ -0,0 +1,36 @@ + + + + + +

    This example uses errorpage directive

    +
    +

    Select my favourite car.

    +
    + + +
    +
    + + + diff --git a/webapps/examples/jsp/error/errorpge.jsp b/webapps/examples/jsp/error/errorpge.jsp new file mode 100644 index 000000000..c91ce6130 --- /dev/null +++ b/webapps/examples/jsp/error/errorpge.jsp @@ -0,0 +1,24 @@ + + + + + + <%@ page isErrorPage="true" %> +

    The exception <%= exception.getMessage() %> tells me you + made a wrong choice. + + diff --git a/webapps/examples/jsp/forward/forward.jsp b/webapps/examples/jsp/forward/forward.jsp new file mode 100644 index 000000000..4a37fd060 --- /dev/null +++ b/webapps/examples/jsp/forward/forward.jsp @@ -0,0 +1,22 @@ + + + +<% + double freeMem = Runtime.getRuntime().freeMemory(); + double totlMem = Runtime.getRuntime().totalMemory(); + double percent = freeMem/totlMem; + if (percent < 0.5) { +%> + + + +<% } else { %> + + + +<% } %> + + diff --git a/webapps/examples/jsp/forward/fwd.html b/webapps/examples/jsp/forward/fwd.html new file mode 100644 index 000000000..980a53f56 --- /dev/null +++ b/webapps/examples/jsp/forward/fwd.html @@ -0,0 +1,18 @@ + + + +Untitled Document + + + + +

    + +

    Source Code for Forward Example +

    + + + diff --git a/webapps/examples/jsp/forward/one.jsp b/webapps/examples/jsp/forward/one.jsp new file mode 100644 index 000000000..4afe6f28c --- /dev/null +++ b/webapps/examples/jsp/forward/one.jsp @@ -0,0 +1,11 @@ + + + + + + +VM Memory usage < 50%. + \ No newline at end of file diff --git a/webapps/examples/jsp/forward/two.html b/webapps/examples/jsp/forward/two.html new file mode 100644 index 000000000..3bc29170d --- /dev/null +++ b/webapps/examples/jsp/forward/two.html @@ -0,0 +1,11 @@ + + + + + + +VM Memory usage > 50%. + \ No newline at end of file diff --git a/webapps/examples/jsp/images/code.gif b/webapps/examples/jsp/images/code.gif new file mode 100644 index 000000000..93af2cd13 Binary files /dev/null and b/webapps/examples/jsp/images/code.gif differ diff --git a/webapps/examples/jsp/images/execute.gif b/webapps/examples/jsp/images/execute.gif new file mode 100644 index 000000000..f64d70fd2 Binary files /dev/null and b/webapps/examples/jsp/images/execute.gif differ diff --git a/webapps/examples/jsp/images/read.gif b/webapps/examples/jsp/images/read.gif new file mode 100644 index 000000000..66cb4e923 Binary files /dev/null and b/webapps/examples/jsp/images/read.gif differ diff --git a/webapps/examples/jsp/images/return.gif b/webapps/examples/jsp/images/return.gif new file mode 100644 index 000000000..af4f68f4a Binary files /dev/null and b/webapps/examples/jsp/images/return.gif differ diff --git a/webapps/examples/jsp/include/foo.html b/webapps/examples/jsp/include/foo.html new file mode 100644 index 000000000..47d146422 --- /dev/null +++ b/webapps/examples/jsp/include/foo.html @@ -0,0 +1,16 @@ + +To get the current time in ms diff --git a/webapps/examples/jsp/include/foo.jsp b/webapps/examples/jsp/include/foo.jsp new file mode 100644 index 000000000..0130b0716 --- /dev/null +++ b/webapps/examples/jsp/include/foo.jsp @@ -0,0 +1,20 @@ + + + + + +<%= System.currentTimeMillis() %> diff --git a/webapps/examples/jsp/include/inc.html b/webapps/examples/jsp/include/inc.html new file mode 100644 index 000000000..1bb3fb3e5 --- /dev/null +++ b/webapps/examples/jsp/include/inc.html @@ -0,0 +1,29 @@ + + + +Untitled Document + + + + +

    + +

    Source Code for Include Example +

    + + + diff --git a/webapps/examples/jsp/include/include.jsp b/webapps/examples/jsp/include/include.jsp new file mode 100644 index 000000000..fef97361d --- /dev/null +++ b/webapps/examples/jsp/include/include.jsp @@ -0,0 +1,34 @@ + + + + + + + +<%@ page buffer="5kb" autoFlush="false" %> + +

    In place evaluation of another JSP which gives you the current time: + +<%@ include file="foo.jsp" %> + +

    by including the output of another JSP: + + + +:-) + + diff --git a/webapps/examples/jsp/index.html b/webapps/examples/jsp/index.html new file mode 100644 index 000000000..546c2b6f4 --- /dev/null +++ b/webapps/examples/jsp/index.html @@ -0,0 +1,373 @@ + + +\ + + + + + JSP Examples + + + +JSP +Samples +

    This is a collection of samples demonstrating the usage of different +parts of the Java Server Pages (JSP) specification. Both JSP 2.0 and +JSP 1.2 examples are presented below. +

    These examples will only work when these pages are being served by a +servlet engine; of course, we recommend +Tomcat. +They will not work if you are viewing these pages via a +"file://..." URL. +

    To navigate your way through the examples, the following icons will +help: +
      + + + + + + + + + + + + + + + + + + + + + +
    Execute the example
    Look at the source code for the example
    Return to this screen
    + +

    Tip: For session scoped beans to work, the cookies must be enabled. +This can be done using browser options. +
      +
    +JSP 2.0 Examples
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Expression Language
    Basic ArithmeticExecuteSource
    Basic ComparisonsExecuteSource
    Implicit ObjectsExecuteSource
    FunctionsExecuteSource

    SimpleTag Handlers and JSP Fragments
    Hello World TagExecuteSource
    Repeat TagExecuteSource
    Book ExampleExecuteSource

    Tag Files
    Hello World Tag FileExecuteSource
    Panel Tag FileExecuteSource
    Display Products ExampleExecuteSource

    New JSP XML Syntax (.jspx)
    XHTML Basic ExampleExecuteSource
    SVG (Scalable Vector Graphics)ExecuteSource

    Other JSP 2.0 Features
    <jsp:attribute> and <jsp:body>ExecuteSource
    Shuffle ExampleExecuteSource
    Attributes With Dynamic NamesExecuteSource
    JSP ConfigurationExecuteSource
    + +
    +JSP 1.2 Examples
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Numberguess ExecuteSource
    Date ExecuteSource
    SnoopExecuteSource
    ErrorPage ExecuteSource
    Carts ExecuteSource
    Checkbox ExecuteSource
    Color ExecuteSource
    Calendar ExecuteSource
    Include ExecuteSource
    Forward ExecuteSource
    Plugin ExecuteSource
    JSP-Servlet-JSP ExecuteSource
    Custom tag exampleExecuteSource
    XML syntax exampleExecuteSource
    + +
    +Tag Plugins
    + + + + + + + + + + + + + + + + + + + + +
    If  + + Execute + + + Source +
    ForEach  + + Execute + + + Source +
    Choose  + + Execute + + + Source +
    + + + diff --git a/webapps/examples/jsp/jsp2/el/basic-arithmetic.html b/webapps/examples/jsp/jsp2/el/basic-arithmetic.html new file mode 100644 index 000000000..fe9c71978 --- /dev/null +++ b/webapps/examples/jsp/jsp2/el/basic-arithmetic.html @@ -0,0 +1,29 @@ + + + +View Source Code + + + + +

    + +

    Source Code for Basic Arithmetic Example +

    + + + diff --git a/webapps/examples/jsp/jsp2/el/basic-arithmetic.jsp b/webapps/examples/jsp/jsp2/el/basic-arithmetic.jsp new file mode 100644 index 000000000..86ffb1525 --- /dev/null +++ b/webapps/examples/jsp/jsp2/el/basic-arithmetic.jsp @@ -0,0 +1,87 @@ + + + + JSP 2.0 Expression Language - Basic Arithmetic + + +

    JSP 2.0 Expression Language - Basic Arithmetic

    +
    + This example illustrates basic Expression Language arithmetic. + Addition (+), subtraction (-), multiplication (*), division (/ or div), + and modulus (% or mod) are all supported. Error conditions, like + division by zero, are handled gracefully. +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    EL ExpressionResult
    \${1}${1}
    \${1 + 2}${1 + 2}
    \${1.2 + 2.3}${1.2 + 2.3}
    \${1.2E4 + 1.4}${1.2E4 + 1.4}
    \${-4 - 2}${-4 - 2}
    \${21 * 2}${21 * 2}
    \${3/4}${3/4}
    \${3 div 4}${3 div 4}
    \${3/0}${3/0}
    \${10%4}${10%4}
    \${10 mod 4}${10 mod 4}
    \${(1==2) ? 3 : 4}${(1==2) ? 3 : 4}
    +
    +
    + + diff --git a/webapps/examples/jsp/jsp2/el/basic-comparisons.html b/webapps/examples/jsp/jsp2/el/basic-comparisons.html new file mode 100644 index 000000000..22cd17490 --- /dev/null +++ b/webapps/examples/jsp/jsp2/el/basic-comparisons.html @@ -0,0 +1,29 @@ + + + +View Source Code + + + + +

    + +

    Source Code for Basic Comparisons Example +

    + + + diff --git a/webapps/examples/jsp/jsp2/el/basic-comparisons.jsp b/webapps/examples/jsp/jsp2/el/basic-comparisons.jsp new file mode 100644 index 000000000..1e85dba30 --- /dev/null +++ b/webapps/examples/jsp/jsp2/el/basic-comparisons.jsp @@ -0,0 +1,115 @@ + + + + JSP 2.0 Expression Language - Basic Comparisons + + +

    JSP 2.0 Expression Language - Basic Comparisons

    +
    + This example illustrates basic Expression Language comparisons. + The following comparison operators are supported: +
      +
    • Less-than (< or lt)
    • +
    • Greater-than (> or gt)
    • +
    • Less-than-or-equal (<= or le)
    • +
    • Greater-than-or-equal (>= or ge)
    • +
    • Equal (== or eq)
    • +
    • Not Equal (!= or ne)
    • +
    +
    + Numeric + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    EL ExpressionResult
    \${1 < 2}${1 < 2}
    \${1 lt 2}${1 lt 2}
    \${1 > (4/2)}${1 > (4/2)}
    \${1 > (4/2)}${1 > (4/2)}
    \${4.0 >= 3}${4.0 >= 3}
    \${4.0 ge 3}${4.0 ge 3}
    \${4 <= 3}${4 <= 3}
    \${4 le 3}${4 le 3}
    \${100.0 == 100}${100.0 == 100}
    \${100.0 eq 100}${100.0 eq 100}
    \${(10*10) != 100}${(10*10) != 100}
    \${(10*10) ne 100}${(10*10) ne 100}
    +
    +
    + Alphabetic + + + + + + + + + + + + + + + + + + +
    EL ExpressionResult
    \${'a' < 'b'}${'a' < 'b'}
    \${'hip' > 'hit'}${'hip' > 'hit'}
    \${'4' > 3}${'4' > 3}
    +
    +
    + + diff --git a/webapps/examples/jsp/jsp2/el/functions.html b/webapps/examples/jsp/jsp2/el/functions.html new file mode 100644 index 000000000..59b035043 --- /dev/null +++ b/webapps/examples/jsp/jsp2/el/functions.html @@ -0,0 +1,31 @@ + + + +View Source Code + + + + +

    + +

    Source Code for functions.jsp +

    +

    Source Code for Functions.java +

    + + + diff --git a/webapps/examples/jsp/jsp2/el/functions.jsp b/webapps/examples/jsp/jsp2/el/functions.jsp new file mode 100644 index 000000000..b6c53df1c --- /dev/null +++ b/webapps/examples/jsp/jsp2/el/functions.jsp @@ -0,0 +1,65 @@ + +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> +<%@ taglib prefix="my" uri="http://jakarta.apache.org/tomcat/jsp2-example-taglib"%> + + + + JSP 2.0 Expression Language - Functions + + +

    JSP 2.0 Expression Language - Functions

    +
    + An upgrade from the JSTL expression language, the JSP 2.0 EL also + allows for simple function invocation. Functions are defined + by tag libraries and are implemented by a Java programmer as + static methods. + +
    + Change Parameter +
    + foo = + +
    +
    + + + + + + + + + + + + + + + + + + + + + + +
    EL ExpressionResult
    \${param["foo"]}${fn:escapeXml(param["foo"])} 
    \${my:reverse(param["foo"])}${my:reverse(fn:escapeXml(param["foo"]))} 
    \${my:reverse(my:reverse(param["foo"]))}${my:reverse(my:reverse(fn:escapeXml(param["foo"])))} 
    \${my:countVowels(param["foo"])}${my:countVowels(fn:escapeXml(param["foo"]))} 
    +
    +
    + + + diff --git a/webapps/examples/jsp/jsp2/el/implicit-objects.html b/webapps/examples/jsp/jsp2/el/implicit-objects.html new file mode 100644 index 000000000..391ecdbb7 --- /dev/null +++ b/webapps/examples/jsp/jsp2/el/implicit-objects.html @@ -0,0 +1,19 @@ + + + +View Source Code + + + + +

    +

    + +

    Source Code for Implicit Objects Example +

    + + + diff --git a/webapps/examples/jsp/jsp2/el/implicit-objects.jsp b/webapps/examples/jsp/jsp2/el/implicit-objects.jsp new file mode 100644 index 000000000..992aa1d4b --- /dev/null +++ b/webapps/examples/jsp/jsp2/el/implicit-objects.jsp @@ -0,0 +1,88 @@ + +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> + + + + JSP 2.0 Expression Language - Implicit Objects + + +

    JSP 2.0 Expression Language - Implicit Objects

    +
    + This example illustrates some of the implicit objects available + in the Expression Lanaguage. The following implicit objects are + available (not all illustrated here): +
      +
    • pageContext - the PageContext object
    • +
    • pageScope - a Map that maps page-scoped attribute names to + their values
    • +
    • requestScope - a Map that maps request-scoped attribute names + to their values
    • +
    • sessionScope - a Map that maps session-scoped attribute names + to their values
    • +
    • applicationScope - a Map that maps application-scoped attribute + names to their values
    • +
    • param - a Map that maps parameter names to a single String + parameter value
    • +
    • paramValues - a Map that maps parameter names to a String[] of + all values for that parameter
    • +
    • header - a Map that maps header names to a single String + header value
    • +
    • headerValues - a Map that maps header names to a String[] of + all values for that header
    • +
    • initParam - a Map that maps context initialization parameter + names to their String parameter value
    • +
    • cookie - a Map that maps cookie names to a single Cookie object.
    • +
    + +
    + Change Parameter +
    + foo = + +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    EL ExpressionResult
    \${param.foo}${fn:escapeXml(param["foo"])} 
    \${param["foo"]}${fn:escapeXml(param["foo"])} 
    \${header["host"]}${header["host"]}
    \${header["accept"]}${header["accept"]}
    \${header["user-agent"]}${header["user-agent"]}
    +
    +
    + + diff --git a/webapps/examples/jsp/jsp2/jspattribute/jspattribute.html b/webapps/examples/jsp/jsp2/jspattribute/jspattribute.html new file mode 100644 index 000000000..5faea3926 --- /dev/null +++ b/webapps/examples/jsp/jsp2/jspattribute/jspattribute.html @@ -0,0 +1,36 @@ + + + +View Source Code + + + + +

    +

    + +

    Source Code for jspattribute.jsp +

    + +

    Source Code for HelloWorldSimpleTag.java +

    + +

    Source Code for FooBean.java +

    + + + diff --git a/webapps/examples/jsp/jsp2/jspattribute/jspattribute.jsp b/webapps/examples/jsp/jsp2/jspattribute/jspattribute.jsp new file mode 100644 index 000000000..22b705e1b --- /dev/null +++ b/webapps/examples/jsp/jsp2/jspattribute/jspattribute.jsp @@ -0,0 +1,45 @@ + +<%@ taglib prefix="my" uri="http://jakarta.apache.org/tomcat/jsp2-example-taglib"%> + + + + JSP 2.0 Examples - jsp:attribute and jsp:body + + +

    JSP 2.0 Examples - jsp:attribute and jsp:body

    +
    +

    The new <jsp:attribute> and <jsp:body> + standard actions can be used to specify the value of any standard + action or custom action attribute.

    +

    This example uses the <jsp:attribute> + standard action to use the output of a custom action invocation + (one that simply outputs "Hello, World!") to set the value of a + bean property. This would normally require an intermediary + step, such as using JSTL's <c:set> action.

    +
    + + Bean created! Setting foo.bar...
    + + + + + +
    +
    + Result: ${foo.bar} + + diff --git a/webapps/examples/jsp/jsp2/jspattribute/shuffle.html b/webapps/examples/jsp/jsp2/jspattribute/shuffle.html new file mode 100644 index 000000000..907c5aa42 --- /dev/null +++ b/webapps/examples/jsp/jsp2/jspattribute/shuffle.html @@ -0,0 +1,36 @@ + + + +View Source Code + + + + +

    +

    + +

    Source Code for shuffle.jsp +

    + +

    Source Code for ShuffleSimpleTag.java +

    + +

    Source Code for TileSimpleTag.java +

    + + + diff --git a/webapps/examples/jsp/jsp2/jspattribute/shuffle.jsp b/webapps/examples/jsp/jsp2/jspattribute/shuffle.jsp new file mode 100644 index 000000000..4f139fdae --- /dev/null +++ b/webapps/examples/jsp/jsp2/jspattribute/shuffle.jsp @@ -0,0 +1,89 @@ + +<%@ taglib prefix="my" uri="http://jakarta.apache.org/tomcat/jsp2-example-taglib"%> + + + + JSP 2.0 Examples - Shuffle Example + + +

    JSP 2.0 Examples - Shuffle Example

    +
    +

    Try reloading the page a few times. Both the rows and the columns + are shuffled and appear different each time.

    +

    Here's how the code works. The SimpleTag handler called + <my:shuffle> accepts three attributes. Each attribute is a + JSP Fragment, meaning it is a fragment of JSP code that can be + dynamically executed by the shuffle tag handler on demand. The + shuffle tag handler executes the three fragments in a random order. + To shuffle both the rows and the columns, the shuffle tag is used + with itself as a parameter.

    +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    +
    + + diff --git a/webapps/examples/jsp/jsp2/jspx/basic.html b/webapps/examples/jsp/jsp2/jspx/basic.html new file mode 100644 index 000000000..db2427b81 --- /dev/null +++ b/webapps/examples/jsp/jsp2/jspx/basic.html @@ -0,0 +1,30 @@ + + + +View Source Code + + + + +

    + +

    Source Code for XHTML Basic Example +

    + + + diff --git a/webapps/examples/jsp/jsp2/jspx/basic.jspx b/webapps/examples/jsp/jsp2/jspx/basic.jspx new file mode 100644 index 000000000..75394fcbf --- /dev/null +++ b/webapps/examples/jsp/jsp2/jspx/basic.jspx @@ -0,0 +1,30 @@ + + + + JSPX - XHTML Basic Example + + +

    JSPX - XHTML Basic Example

    +
    + This example illustrates how to use JSPX to produce an XHTML basic + document suitable for use with mobile phones, televisions, + PDAs, vending machines, pagers, car navigation systems, + mobile game machines, digital book readers, smart watches, etc. +

    + JSPX lets you create dynamic documents in a pure XML syntax compatible + with existing XML tools. The XML syntax in JSP 1.2 was awkward and + required &lt;jsp:root&gt; to be the root element of the document. + This is no longer the case in JSP 2.0. +

    + This particular example uses a tag file to produce the DOCTYPE and + namespace declarations to make the output of this page a valid XHTML + Basic document. +

    + Just to prove this is live, here's some dynamic content: + + + + diff --git a/webapps/examples/jsp/jsp2/jspx/svgexample.html b/webapps/examples/jsp/jsp2/jspx/svgexample.html new file mode 100644 index 000000000..7f954597b --- /dev/null +++ b/webapps/examples/jsp/jsp2/jspx/svgexample.html @@ -0,0 +1,51 @@ + + + + JSP 2.0 SVG Example + + +

    JSP 2.0 SVG Example

    +
    + This example uses JSP 2.0's new, simplified JSPX syntax to render a + Scalable Vector Graphics (SVG) document. When you view the source, + notice the lack of a <jsp:root> element! The text to be rendered + can be modified by changing the value of the name parameter. +

    + SVG has many potential uses, such as searchable images, or images + customized with the name of your site's visitor (e.g. a "Susan's Store" + tab image). JSPX is a natural fit for generating dynamic XML content + such as SVG. +

    + To execute this example, follow these steps: +

      +
    1. Download Batik, + or any other SVG viewer.
    2. +
    3. Copy the following URL: + + http://localhost:8080/jsp-examples/jsp2/jspx/textRotate.jspx?name=JSPX +
    4. +
    5. Paste the URL into Batik's Location field and press Enter
    6. +
    7. Customize by changing the name=JSPX parameter
    8. +
    +
    + The following is a screenshot of the resulting image, for those that + don't have an SVG viewer: +
    + +
    + + diff --git a/webapps/examples/jsp/jsp2/jspx/textRotate.html b/webapps/examples/jsp/jsp2/jspx/textRotate.html new file mode 100644 index 000000000..1874ecbbf --- /dev/null +++ b/webapps/examples/jsp/jsp2/jspx/textRotate.html @@ -0,0 +1,31 @@ + + + +View Source Code + + + + +

    + +

    Source Code for SVG (Scalable Vector Graphics) +Example +

    + + + diff --git a/webapps/examples/jsp/jsp2/jspx/textRotate.jpg b/webapps/examples/jsp/jsp2/jspx/textRotate.jpg new file mode 100644 index 000000000..9e987367b Binary files /dev/null and b/webapps/examples/jsp/jsp2/jspx/textRotate.jpg differ diff --git a/webapps/examples/jsp/jsp2/jspx/textRotate.jspx b/webapps/examples/jsp/jsp2/jspx/textRotate.jspx new file mode 100644 index 000000000..1d2c3e3ac --- /dev/null +++ b/webapps/examples/jsp/jsp2/jspx/textRotate.jspx @@ -0,0 +1,36 @@ + + + + JSP 2.0 JSPX + + + + + JSP 2.0 XML Syntax (.jspx) Demo + + Try changing the name parameter! + + + + <g opacity="0.95" transform="scale(1.05) rotate(15)"> + + ${name} + + + </g> + + ${name} + + + diff --git a/webapps/examples/jsp/jsp2/misc/coda.jspf b/webapps/examples/jsp/jsp2/misc/coda.jspf new file mode 100644 index 000000000..edbf9e983 --- /dev/null +++ b/webapps/examples/jsp/jsp2/misc/coda.jspf @@ -0,0 +1,5 @@ +
    +
    +This banner included with <include-coda> +
    +
    diff --git a/webapps/examples/jsp/jsp2/misc/config.html b/webapps/examples/jsp/jsp2/misc/config.html new file mode 100644 index 000000000..160d7785d --- /dev/null +++ b/webapps/examples/jsp/jsp2/misc/config.html @@ -0,0 +1,34 @@ + + + +View Source Code + + + + +

    +

    + +

    Source Code for config.jsp +

    +

    Source Code for prelude.jspf +

    +

    Source Code for coda.jspf +

    + + + diff --git a/webapps/examples/jsp/jsp2/misc/config.jsp b/webapps/examples/jsp/jsp2/misc/config.jsp new file mode 100644 index 000000000..791a08712 --- /dev/null +++ b/webapps/examples/jsp/jsp2/misc/config.jsp @@ -0,0 +1,31 @@ + +<%@ taglib prefix="my" uri="http://jakarta.apache.org/tomcat/jsp2-example-taglib"%> +

    JSP 2.0 Examples - JSP Configuration

    +
    +

    Using a <jsp-property-group> element in the web.xml + deployment descriptor, this JSP page has been configured in the + following ways:

    +
      +
    • Uses <include-prelude> to include the top banner.
    • +
    • Uses <include-coda> to include the bottom banner.
    • +
    • Uses <scripting-invalid> true to disable + <% scripting %> elements
    • +
    • Uses <el-ignored> true to disable ${EL} elements
    • +
    • Uses <page-encoding> ISO-8859-1 to set the page encoding (though this is the default anyway)
    • +
    + There are various other configuration options that can be used. + diff --git a/webapps/examples/jsp/jsp2/misc/dynamicattrs.html b/webapps/examples/jsp/jsp2/misc/dynamicattrs.html new file mode 100644 index 000000000..307072a2b --- /dev/null +++ b/webapps/examples/jsp/jsp2/misc/dynamicattrs.html @@ -0,0 +1,32 @@ + + + +View Source Code + + + + +

    +

    + +

    Source Code for dynamicattrs.jsp +

    +

    Source Code for EchoAttributesTag.java +

    + + + diff --git a/webapps/examples/jsp/jsp2/misc/dynamicattrs.jsp b/webapps/examples/jsp/jsp2/misc/dynamicattrs.jsp new file mode 100644 index 000000000..8721108aa --- /dev/null +++ b/webapps/examples/jsp/jsp2/misc/dynamicattrs.jsp @@ -0,0 +1,43 @@ + +<%@ taglib prefix="my" uri="http://jakarta.apache.org/tomcat/jsp2-example-taglib"%> + + + JSP 2.0 Examples - Dynamic Attributes + + +

    JSP 2.0 Examples - Dynamic Attributes

    +
    +

    This JSP page invokes a custom tag that accepts a dynamic set + of attributes. The tag echoes the name and value of all attributes + passed to it.

    +
    +

    Invocation 1 (six attributes)

    +
      + +
    +

    Invocation 2 (zero attributes)

    +
      + +
    +

    Invocation 3 (three attributes)

    +
      + +
    + + diff --git a/webapps/examples/jsp/jsp2/misc/prelude.jspf b/webapps/examples/jsp/jsp2/misc/prelude.jspf new file mode 100644 index 000000000..1ff2be7a7 --- /dev/null +++ b/webapps/examples/jsp/jsp2/misc/prelude.jspf @@ -0,0 +1,5 @@ +
    +
    +This banner included with <include-prelude> +
    +
    diff --git a/webapps/examples/jsp/jsp2/simpletag/book.html b/webapps/examples/jsp/jsp2/simpletag/book.html new file mode 100644 index 000000000..ec8a4c9e0 --- /dev/null +++ b/webapps/examples/jsp/jsp2/simpletag/book.html @@ -0,0 +1,36 @@ + + + +View Source Code + + + + +

    +

    + +

    Source Code for the Book Example JSP +

    +

    Source Code for the FindBook SimpleTag Handler +

    +

    Source Code for BookBean +

    +

    Source Code for the EL Functions +

    + + + diff --git a/webapps/examples/jsp/jsp2/simpletag/book.jsp b/webapps/examples/jsp/jsp2/simpletag/book.jsp new file mode 100644 index 000000000..1f2c4c747 --- /dev/null +++ b/webapps/examples/jsp/jsp2/simpletag/book.jsp @@ -0,0 +1,54 @@ + +<%@ taglib prefix="my" uri="/WEB-INF/jsp2/jsp2-example-taglib.tld" %> + + + JSP 2.0 Examples - Book SimpleTag Handler + + +

    JSP 2.0 Examples - Book SimpleTag Handler

    +
    +

    Illustrates a semi-realistic use of SimpleTag and the Expression + Language. First, a <my:findBook> tag is invoked to populate + the page context with a BookBean. Then, the books fields are printed + in all caps.

    +
    + Result:
    + + + + + + + + + + + + + + + + + + + + + + +
    FieldValueCapitalized
    Title${book.title}${my:caps(book.title)}
    Author${book.author}${my:caps(book.author)}
    ISBN${book.isbn}${my:caps(book.isbn)}
    + + diff --git a/webapps/examples/jsp/jsp2/simpletag/hello.html b/webapps/examples/jsp/jsp2/simpletag/hello.html new file mode 100644 index 000000000..943b0aa21 --- /dev/null +++ b/webapps/examples/jsp/jsp2/simpletag/hello.html @@ -0,0 +1,32 @@ + + + +View Source Code + + + + +

    +

    + +

    Source Code for the Hello World Tag Example JSP +

    +

    Source Code for the Hello World SimpleTag Handler +

    + + + diff --git a/webapps/examples/jsp/jsp2/simpletag/hello.jsp b/webapps/examples/jsp/jsp2/simpletag/hello.jsp new file mode 100644 index 000000000..e86a8c9f1 --- /dev/null +++ b/webapps/examples/jsp/jsp2/simpletag/hello.jsp @@ -0,0 +1,30 @@ + +<%@ taglib prefix="mytag" uri="/WEB-INF/jsp2/jsp2-example-taglib.tld" %> + + + JSP 2.0 Examples - Hello World SimpleTag Handler + + +

    JSP 2.0 Examples - Hello World SimpleTag Handler

    +
    +

    This tag handler simply echos "Hello, World!" It's an example of + a very basic SimpleTag handler with no body.

    +
    + Result: + + + diff --git a/webapps/examples/jsp/jsp2/simpletag/repeat.html b/webapps/examples/jsp/jsp2/simpletag/repeat.html new file mode 100644 index 000000000..6ddc39de0 --- /dev/null +++ b/webapps/examples/jsp/jsp2/simpletag/repeat.html @@ -0,0 +1,32 @@ + + + +View Source Code + + + + +

    +

    + +

    Source Code for the Repeat Tag Example JSP +

    +

    Source Code for the Repeat SimpleTag Handler +

    + + + diff --git a/webapps/examples/jsp/jsp2/simpletag/repeat.jsp b/webapps/examples/jsp/jsp2/simpletag/repeat.jsp new file mode 100644 index 000000000..04d46301a --- /dev/null +++ b/webapps/examples/jsp/jsp2/simpletag/repeat.jsp @@ -0,0 +1,38 @@ + +<%@ taglib prefix="mytag" uri="/WEB-INF/jsp2/jsp2-example-taglib.tld" %> + + + JSP 2.0 Examples - Repeat SimpleTag Handler + + +

    JSP 2.0 Examples - Repeat SimpleTag Handler

    +
    +

    This tag handler accepts a "num" parameter and repeats the body of the + tag "num" times. It's a simple example, but the implementation of + such a tag in JSP 2.0 is substantially simpler than the equivalent + JSP 1.2-style classic tag handler.

    +

    The body of the tag is encapsulated in a "JSP Fragment" and passed + to the tag handler, which then executes it five times, inside a + for loop. The tag handler passes in the current invocation in a + scoped variable called count, which can be accessed using the EL.

    +
    + Result:
    + + Invocation ${count} of 5
    +
    + + diff --git a/webapps/examples/jsp/jsp2/tagfiles/hello.html b/webapps/examples/jsp/jsp2/tagfiles/hello.html new file mode 100644 index 000000000..f5dc2c2f8 --- /dev/null +++ b/webapps/examples/jsp/jsp2/tagfiles/hello.html @@ -0,0 +1,32 @@ + + + +View Source Code + + + + +

    +

    + +

    Source Code for hello.jsp +

    +

    Source Code for helloWorld.tag +

    + + + diff --git a/webapps/examples/jsp/jsp2/tagfiles/hello.jsp b/webapps/examples/jsp/jsp2/tagfiles/hello.jsp new file mode 100644 index 000000000..4fd06b2f8 --- /dev/null +++ b/webapps/examples/jsp/jsp2/tagfiles/hello.jsp @@ -0,0 +1,34 @@ + +<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %> + + + JSP 2.0 Examples - Hello World Using a Tag File + + +

    JSP 2.0 Examples - Hello World Using a Tag File

    +
    +

    This JSP page invokes a custom tag that simply echos "Hello, World!" + The custom tag is generated from a tag file in the /WEB-INF/tags + directory.

    +

    Notice that we did not need to write a TLD for this tag. We just + created /WEB-INF/tags/helloWorld.tag, imported it using the taglib + directive, and used it!

    +
    + Result: + + + diff --git a/webapps/examples/jsp/jsp2/tagfiles/panel.html b/webapps/examples/jsp/jsp2/tagfiles/panel.html new file mode 100644 index 000000000..c3db5c797 --- /dev/null +++ b/webapps/examples/jsp/jsp2/tagfiles/panel.html @@ -0,0 +1,32 @@ + + + +View Source Code + + + + +

    +

    + +

    Source Code for panel.jsp +

    +

    Source Code for panel.tag +

    + + + diff --git a/webapps/examples/jsp/jsp2/tagfiles/panel.jsp b/webapps/examples/jsp/jsp2/tagfiles/panel.jsp new file mode 100644 index 000000000..af04e43f1 --- /dev/null +++ b/webapps/examples/jsp/jsp2/tagfiles/panel.jsp @@ -0,0 +1,57 @@ + +<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %> + + + JSP 2.0 Examples - Panels using Tag Files + + +

    JSP 2.0 Examples - Panels using Tag Files

    +
    +

    This JSP page invokes a custom tag that draws a + panel around the contents of the tag body. Normally, such a tag + implementation would require a Java class with many println() statements, + outputting HTML. Instead, we can use a .tag file as a template, + and we don't need to write a single line of Java or even a TLD!

    +
    + + + + + + +
    + + First panel.
    +
    +
    + + Second panel.
    + Second panel.
    + Second panel.
    + Second panel.
    +
    +
    + + Third panel.
    + + A panel in a panel. + + Third panel.
    +
    +
    + + diff --git a/webapps/examples/jsp/jsp2/tagfiles/products.html b/webapps/examples/jsp/jsp2/tagfiles/products.html new file mode 100644 index 000000000..b03e84d9f --- /dev/null +++ b/webapps/examples/jsp/jsp2/tagfiles/products.html @@ -0,0 +1,21 @@ + + + +View Source Code + + + + +

    +

    + +

    Source Code for products.jsp +

    +

    Source Code for displayProducts.tag +

    + + + diff --git a/webapps/examples/jsp/jsp2/tagfiles/products.jsp b/webapps/examples/jsp/jsp2/tagfiles/products.jsp new file mode 100644 index 000000000..9fa7355d7 --- /dev/null +++ b/webapps/examples/jsp/jsp2/tagfiles/products.jsp @@ -0,0 +1,53 @@ + +<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %> + + + JSP 2.0 Examples - Display Products Tag File + + +

    JSP 2.0 Examples - Display Products Tag File

    +
    +

    This JSP page invokes a tag file that displays a listing of + products. The custom tag accepts two fragments that enable + customization of appearance. One for when the product is on sale + and one for normal price.

    +

    The tag is invoked twice, using different styles

    +
    +

    Products

    + + + Item: ${name}
    + Price: ${price} +
    + + Item: ${name}
    + Was: ${origPrice}
    + Now: ${salePrice} +
    +
    +
    +

    Products (Same tag, alternate style)

    + + + ${name} @ ${price} ea. + + + ${name} @ ${salePrice} ea. (was: ${origPrice}) + + + + diff --git a/webapps/examples/jsp/jsptoserv/hello.jsp b/webapps/examples/jsp/jsptoserv/hello.jsp new file mode 100644 index 000000000..f1807f371 --- /dev/null +++ b/webapps/examples/jsp/jsptoserv/hello.jsp @@ -0,0 +1,25 @@ + + + + +

    +I have been invoked by +<% out.print (request.getAttribute("servletName").toString()); %> +Servlet. +

    + + \ No newline at end of file diff --git a/webapps/examples/jsp/jsptoserv/jsptoservlet.jsp b/webapps/examples/jsp/jsptoserv/jsptoservlet.jsp new file mode 100644 index 000000000..d05f9196c --- /dev/null +++ b/webapps/examples/jsp/jsptoserv/jsptoservlet.jsp @@ -0,0 +1,22 @@ + + + + + + + + \ No newline at end of file diff --git a/webapps/examples/jsp/jsptoserv/jts.html b/webapps/examples/jsp/jsptoserv/jts.html new file mode 100644 index 000000000..7f83a45dd --- /dev/null +++ b/webapps/examples/jsp/jsptoserv/jts.html @@ -0,0 +1,33 @@ + + + + +Untitled Document + + + + +

    + +

    Source Code for JSP calling servlet +

    + +

    Source Code for Servlet calling JSP +

    + + + diff --git a/webapps/examples/jsp/num/numguess.html b/webapps/examples/jsp/num/numguess.html new file mode 100644 index 000000000..348e773f9 --- /dev/null +++ b/webapps/examples/jsp/num/numguess.html @@ -0,0 +1,33 @@ + + + +Untitled Document + + + + +

    + +

    Source Code for Numguess Example +

    + + + diff --git a/webapps/examples/jsp/num/numguess.jsp b/webapps/examples/jsp/num/numguess.jsp new file mode 100644 index 000000000..f1b8e0276 --- /dev/null +++ b/webapps/examples/jsp/num/numguess.jsp @@ -0,0 +1,68 @@ + + +<%@ page import = "num.NumberGuessBean" %> + + + + + +Number Guess + + + +<% if (numguess.getSuccess()) { %> + + Congratulations! You got it. + And after just <%= numguess.getNumGuesses() %> tries.

    + + <% numguess.reset(); %> + + Care to try again? + +<% } else if (numguess.getNumGuesses() == 0) { %> + + Welcome to the Number Guess game.

    + + I'm thinking of a number between 1 and 100.

    + +

    + What's your guess? + +
    + +<% } else { %> + + Good guess, but nope. Try <%= numguess.getHint() %>. + + You have made <%= numguess.getNumGuesses() %> guesses.

    + + I'm thinking of a number between 1 and 100.

    + +

    + What's your guess? + +
    + +<% } %> + +
    + + diff --git a/webapps/examples/jsp/plugin/applet/Clock2.java b/webapps/examples/jsp/plugin/applet/Clock2.java new file mode 100644 index 000000000..32edb89d2 --- /dev/null +++ b/webapps/examples/jsp/plugin/applet/Clock2.java @@ -0,0 +1,212 @@ +/* +* Copyright 2004 The Apache Software Foundation +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +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; + } +} diff --git a/webapps/examples/jsp/plugin/plugin.html b/webapps/examples/jsp/plugin/plugin.html new file mode 100644 index 000000000..eee55c607 --- /dev/null +++ b/webapps/examples/jsp/plugin/plugin.html @@ -0,0 +1,29 @@ + + + +Untitled Document + + + + +

    + +

    Source Code for Plugin Example +

    + + + diff --git a/webapps/examples/jsp/plugin/plugin.jsp b/webapps/examples/jsp/plugin/plugin.jsp new file mode 100644 index 000000000..fed5d4e6c --- /dev/null +++ b/webapps/examples/jsp/plugin/plugin.jsp @@ -0,0 +1,33 @@ + + + Plugin example + +

    Current time is :

    + + + Plugin tag OBJECT or EMBED not supported by browser. + + +

    +

    + +The above applet is loaded using the Java Plugin from a jsp page using the +plugin tag. + +

    + + diff --git a/webapps/examples/jsp/security/protected/error.jsp b/webapps/examples/jsp/security/protected/error.jsp new file mode 100644 index 000000000..ff24ca3b0 --- /dev/null +++ b/webapps/examples/jsp/security/protected/error.jsp @@ -0,0 +1,24 @@ + + + +Error Page For Examples + + +Invalid username and/or password, please try +again. + + diff --git a/webapps/examples/jsp/security/protected/index.jsp b/webapps/examples/jsp/security/protected/index.jsp new file mode 100644 index 000000000..56920cebd --- /dev/null +++ b/webapps/examples/jsp/security/protected/index.jsp @@ -0,0 +1,78 @@ + +<% + if (request.getParameter("logoff") != null) { + session.invalidate(); + response.sendRedirect("index.jsp"); + return; + } +%> + + +Protected Page for Examples + + + +You are logged in as remote user <%= request.getRemoteUser() %> +in session <%= session.getId() %>

    + +<% + if (request.getUserPrincipal() != null) { +%> + Your user principal name is + <%= request.getUserPrincipal().getName() %>

    +<% + } 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 + <%= util.HTMLFilter.filter(role) %>

    +<% + } else { +%> + You have not been granted role + <%= util.HTMLFilter.filter(role) %>

    +<% + } + } +%> + +To check whether your username has been granted a particular role, +enter it here: +
    + +
    +

    + +If you have configured this app for form-based authentication, you can log +off by clicking +here. +This should cause you to be returned to the logon page after the redirect +that is performed. + + + diff --git a/webapps/examples/jsp/security/protected/login.jsp b/webapps/examples/jsp/security/protected/login.jsp new file mode 100644 index 000000000..af1e6c11e --- /dev/null +++ b/webapps/examples/jsp/security/protected/login.jsp @@ -0,0 +1,37 @@ + + + +Login Page for Examples + +
    + + + + + + + + + + + + + +
    Username:
    Password:
    +
    + + diff --git a/webapps/examples/jsp/sessions/DummyCart.html b/webapps/examples/jsp/sessions/DummyCart.html new file mode 100644 index 000000000..b6d64f9c2 --- /dev/null +++ b/webapps/examples/jsp/sessions/DummyCart.html @@ -0,0 +1,55 @@ + + + + + +sessions.DummyCart Bean Properties + + +

    +sessions.DummyCart Bean Properties +

    +
    +
    +
    public class DummyCart
    extends Object
    + +

    +


    + +

    + + + + + + + + + +
    +Properties Summary
    + +String +DummyCart:items +
    +
    + +Multi +
    +


    + + diff --git a/webapps/examples/jsp/sessions/carts.html b/webapps/examples/jsp/sessions/carts.html new file mode 100644 index 000000000..ad5c03d2c --- /dev/null +++ b/webapps/examples/jsp/sessions/carts.html @@ -0,0 +1,52 @@ + + + + + carts + + + + + +
    +
    +Please enter item to add or remove: +
    +Add Item: + + + + +

    + + + +
    + +
    + + diff --git a/webapps/examples/jsp/sessions/carts.jsp b/webapps/examples/jsp/sessions/carts.jsp new file mode 100644 index 000000000..d46ceedeb --- /dev/null +++ b/webapps/examples/jsp/sessions/carts.jsp @@ -0,0 +1,43 @@ + + + + + + +<% + cart.processRequest(request); +%> + + + +
    You have the following items in your cart: +
      +<% + String[] items = cart.getItems(); + for (int i=0; i +
    1. <% out.print(util.HTMLFilter.filter(items[i])); %> +<% + } +%> +
    + +
    + +
    +<%@ include file ="/sessions/carts.html" %> + diff --git a/webapps/examples/jsp/sessions/crt.html b/webapps/examples/jsp/sessions/crt.html new file mode 100644 index 000000000..4be80f435 --- /dev/null +++ b/webapps/examples/jsp/sessions/crt.html @@ -0,0 +1,33 @@ + + + + +Untitled Document + + + + +

    + +

    Source Code for Cart Example +

    + +

    Property Sheet for DummyCart +

    + + + diff --git a/webapps/examples/jsp/simpletag/foo.html b/webapps/examples/jsp/simpletag/foo.html new file mode 100644 index 000000000..25b322bfa --- /dev/null +++ b/webapps/examples/jsp/simpletag/foo.html @@ -0,0 +1,29 @@ + + + +Untitled Document + + + + +

    + +

    Source Code for the Simple Tag Example +

    + + + diff --git a/webapps/examples/jsp/simpletag/foo.jsp b/webapps/examples/jsp/simpletag/foo.jsp new file mode 100644 index 000000000..9e3008be8 --- /dev/null +++ b/webapps/examples/jsp/simpletag/foo.jsp @@ -0,0 +1,37 @@ + + + +<%@ taglib uri="http://jakarta.apache.org/tomcat/examples-taglib" prefix="eg"%> + +Radio stations that rock: + +
      + +
    • <%= member %>
    • +
      +
    + + +Did you see me on the stderr window? + + + +Did you see me on the browser window as well? + + + + diff --git a/webapps/examples/jsp/snp/snoop.html b/webapps/examples/jsp/snp/snoop.html new file mode 100644 index 000000000..fffeb093e --- /dev/null +++ b/webapps/examples/jsp/snp/snoop.html @@ -0,0 +1,30 @@ + + + + +Untitled Document + + + + +

    + +

    Source Code for Request Parameters Example +

    + + + diff --git a/webapps/examples/jsp/snp/snoop.jsp b/webapps/examples/jsp/snp/snoop.jsp new file mode 100644 index 000000000..bec02d284 --- /dev/null +++ b/webapps/examples/jsp/snp/snoop.jsp @@ -0,0 +1,55 @@ + + + + +

    Request Information

    + +JSP Request Method: <% out.print(util.HTMLFilter.filter(request.getMethod())); %> +
    +Request URI: <%= request.getRequestURI() %> +
    +Request Protocol: <%= request.getProtocol() %> +
    +Servlet path: <%= request.getServletPath() %> +
    +Path info: <% out.print(util.HTMLFilter.filter(request.getPathInfo())); %> +
    +Query string: <% out.print(util.HTMLFilter.filter(request.getQueryString())); %> +
    +Content length: <%= request.getContentLength() %> +
    +Content type: <% out.print(util.HTMLFilter.filter(request.getContentType())); %> +
    +Server name: <%= request.getServerName() %> +
    +Server port: <%= request.getServerPort() %> +
    +Remote user: <%= request.getRemoteUser() %> +
    +Remote address: <%= request.getRemoteAddr() %> +
    +Remote host: <%= request.getRemoteHost() %> +
    +Authorization scheme: <%= request.getAuthType() %> +
    +Locale: <%= request.getLocale() %> +
    +The browser you are using is <% out.print(util.HTMLFilter.filter(request.getHeader("User-Agent"))); %> +
    +
    + + diff --git a/webapps/examples/jsp/source.jsp b/webapps/examples/jsp/source.jsp new file mode 100644 index 000000000..3d9e9587c --- /dev/null +++ b/webapps/examples/jsp/source.jsp @@ -0,0 +1,19 @@ + +<%@ taglib uri="http://jakarta.apache.org/tomcat/examples-taglib" + prefix="eg" %> + + diff --git a/webapps/examples/jsp/tagplugin/choose.html b/webapps/examples/jsp/tagplugin/choose.html new file mode 100644 index 000000000..9b15c3fa2 --- /dev/null +++ b/webapps/examples/jsp/tagplugin/choose.html @@ -0,0 +1,35 @@ + + + +View Source Code + + + +

    + + + + + +

    + +

    + Source Code for choose.jsp +

    + + + diff --git a/webapps/examples/jsp/tagplugin/choose.jsp b/webapps/examples/jsp/tagplugin/choose.jsp new file mode 100644 index 000000000..8d3545195 --- /dev/null +++ b/webapps/examples/jsp/tagplugin/choose.jsp @@ -0,0 +1,57 @@ + + + + Tag Examples - choose + + +

    Tag Plugin Examples - <c:choose>

    + +
    +
    + Plugin Introductory Notes +
    +
    Brief Instructions for Writing Plugins +

    +
    + + +
    + + <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> + + + # ${index}: + + + One!
    +
    + + Four!
    +
    + + Three!
    +
    + + Huh?
    +
    +
    +
    + + diff --git a/webapps/examples/jsp/tagplugin/foreach.html b/webapps/examples/jsp/tagplugin/foreach.html new file mode 100644 index 000000000..bc56a66b0 --- /dev/null +++ b/webapps/examples/jsp/tagplugin/foreach.html @@ -0,0 +1,35 @@ + + + +View Source Code + + + +

    + + + + + +

    + +

    + Source Code for foreach.jsp +

    + + + diff --git a/webapps/examples/jsp/tagplugin/foreach.jsp b/webapps/examples/jsp/tagplugin/foreach.jsp new file mode 100644 index 000000000..d38e18e2f --- /dev/null +++ b/webapps/examples/jsp/tagplugin/foreach.jsp @@ -0,0 +1,56 @@ + + + + Tag Plugin Examples: forEach + + +

    Tag Plugin Examples - <c:forEach>

    + +
    +
    + Plugin Introductory Notes +
    +
    Brief Instructions for Writing Plugins +

    +
    + + +
    + + <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> + <%@ page import="java.util.Vector" %> + +

    Iterating over a range

    + + ${item} + + + <% Vector v = new Vector(); + v.add("One"); v.add("Two"); v.add("Three"); v.add("Four"); + + pageContext.setAttribute("vector", v); + %> + +

    Iterating over a Vector

    + + + ${item} + + + diff --git a/webapps/examples/jsp/tagplugin/howto.html b/webapps/examples/jsp/tagplugin/howto.html new file mode 100644 index 000000000..e875465ee --- /dev/null +++ b/webapps/examples/jsp/tagplugin/howto.html @@ -0,0 +1,42 @@ + + + + Tag Plugin Implementation +

    How to write tag plugins

    +

    + To write a plugin, you'll need to download the source for Tomcat 5. + There are two steps: +

      +
    1. + Implement the plugin class.

      + This class, which implements + org.apache.jasper.compiler.tagplugin.TagPlugin + instructs Jasper what Java codes to generate in place of the tag + handler calls. + See Javadoc for org.apache.jasper.compiler.tagplugin.TagPlugin + for details. +

    2. + +
    3. + Create the plugin descriptor file WEB-INF/tagPlugins.xml

      + This file + specifies the plugin classes and their corresponding tag handler + classes. +

    4. +
    + + diff --git a/webapps/examples/jsp/tagplugin/if.html b/webapps/examples/jsp/tagplugin/if.html new file mode 100644 index 000000000..385958ace --- /dev/null +++ b/webapps/examples/jsp/tagplugin/if.html @@ -0,0 +1,35 @@ + + + +View Source Code + + + +

    + + + + + +

    + +

    + Source Code for if.jsp +

    + + + diff --git a/webapps/examples/jsp/tagplugin/if.jsp b/webapps/examples/jsp/tagplugin/if.jsp new file mode 100644 index 000000000..56c264790 --- /dev/null +++ b/webapps/examples/jsp/tagplugin/if.jsp @@ -0,0 +1,44 @@ + + + + Tag Plugin Examples: if + + +

    Tag Plugin Examples - <c:if>

    + +
    +
    + Plugin Introductory Notes +
    + Brief Instructions for Wrieting Plugins +

    +
    + + +
    + <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> + +

    Set the test result to a variable

    + + The result of testing for (1==1) is: ${theTruth} + +

    Conditionally execute the body

    + + It's true that (2>0)! + + + diff --git a/webapps/examples/jsp/tagplugin/notes.html b/webapps/examples/jsp/tagplugin/notes.html new file mode 100644 index 000000000..61074502a --- /dev/null +++ b/webapps/examples/jsp/tagplugin/notes.html @@ -0,0 +1,38 @@ + + + + Tag Plugin Introduction +

    Tag Plugins: Introductory Notes

    +

    + Tomcat 5 provides a framework for implementing tag plugins. The + plugins instruct Jasper, at translation time, to replace tag handler + calls with Java scriptlets. + The framework allows tag library authors to implement plugins for + their tags. +

    +

    + Tomcat 5 is released with plugins for several JSTL tags. Note + that these plugins work with JSTL 1.1 as well as JSTL 1.0, though + the examples uses JSTL 1.1 and JSP 2.0. + These plugins are not complete (for instance, some item types not + handled in <c:if>). + They do serve as examples to show plugins in action (just + examine the generated Java files), and how they can be implemented. +

    + + + diff --git a/webapps/examples/jsp/xml/xml.html b/webapps/examples/jsp/xml/xml.html new file mode 100644 index 000000000..1c841289f --- /dev/null +++ b/webapps/examples/jsp/xml/xml.html @@ -0,0 +1,30 @@ + + + + +Untitled Document + + + + +

    + +

    Source Code for XML syntax Example +

    + + + diff --git a/webapps/examples/jsp/xml/xml.jsp b/webapps/examples/jsp/xml/xml.jsp new file mode 100644 index 000000000..d014ff85d --- /dev/null +++ b/webapps/examples/jsp/xml/xml.jsp @@ -0,0 +1,69 @@ + + + + + + + + + String getDateTimeStr(Locale l) { + DateFormat df = SimpleDateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, l); + return df.format(new Date()); + } + + + + + Example JSP in XML format + + + +This is the output of a simple JSP using XML format. +
    + +
    Use a jsp:scriptlet to loop from 1 to 10:
    + +// Note we need to declare CDATA because we don't escape the less than symbol + + + + +
    +]]> + +
    + Use a jsp:expression to write the date and time in the browser's locale: + getDateTimeStr(request.getLocale()) +
    + + + + <p>This sentence is enclosed in a jsp:text element.</p> + + + + +
    diff --git a/webapps/examples/servlets/images/code.gif b/webapps/examples/servlets/images/code.gif new file mode 100644 index 000000000..93af2cd13 Binary files /dev/null and b/webapps/examples/servlets/images/code.gif differ diff --git a/webapps/examples/servlets/images/execute.gif b/webapps/examples/servlets/images/execute.gif new file mode 100644 index 000000000..f64d70fd2 Binary files /dev/null and b/webapps/examples/servlets/images/execute.gif differ diff --git a/webapps/examples/servlets/images/return.gif b/webapps/examples/servlets/images/return.gif new file mode 100644 index 000000000..af4f68f4a Binary files /dev/null and b/webapps/examples/servlets/images/return.gif differ