JavaServerPages\Acquainting\JSP_01

JSP_01 - a simple CGI Variable Display

This document displays the contents of several CGI variables by means of a simple JSP scriptlet within the HTML code.

<%! JspWriter OutStream; // is used to construct the response boolean oddTableRow; // a simple table row "counter" %> <% OutStream = out; oddTableRow = true; showVariable("AUTH_TYPE", request.getAuthType()); showVariable("CONTENT_LENGTH", String.valueOf(request.getContentLength())); showVariable("CONTENT_TYPE", request.getContentType()); // showVariable("DOCUMENT_ROOT", getServletContext().getRealPath("/")); showVariable("PATH_INFO", request.getPathInfo()); showVariable("PATH_TRANSLATED", request.getPathTranslated()); showVariable("QUERY_STRING", request.getQueryString()); showVariable("REMOTE_ADDR", request.getRemoteAddr()); showVariable("REMOTE_HOST", request.getRemoteHost()); showVariable("REMOTE_USER", request.getRemoteUser()); showVariable("REQUEST_METHOD", request.getMethod()); showVariable("SCRIPT_NAME", request.getServletPath()); showVariable("SERVER_NAME", request.getServerName()); showVariable("SERVER_PORT", String.valueOf(request.getServerPort())); showVariable("SERVER_PROTOCOL", request.getProtocol()); // showVariable("SERVER_SOFTWARE", getServletContext().getServerInfo()); %>
Andreas Rozek
<%! /*************************************************************************** * * * showVariable shows the contents of a given CGI variable * * * ***************************************************************************/ public void showVariable (String Name, String Value) { try { OutStream.println(" "); OutStream.println(" "); OutStream.println(" " + Name + ": "); OutStream.print (" "); if (Value == null) { OutStream.print("(not available)"); } else { OutStream.print("\"" + Value + "\""); }; OutStream.println(""); OutStream.println(" "); OutStream.println(" "); } catch (Exception Signal) { /* nop */ }; oddTableRow = !oddTableRow; }; %>