Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
5.2 A Servlet That Shows the CGI Variables
119
SERVER_PROTOCOL
The
SERVER_PROTOCOL
variable indicates the protocol name and ver
sion used in the request line (e.g.,
HTTP/1.0
or
HTTP/1.1
). Access it by
calling
request.getProtocol()
.
SERVER_SOFTWARE
This variable gives identifying information about the Web server. Access
it by means of
getServletContext().getServerInfo()
.
5.2 A Servlet That Shows the CGI
Variables
Listing 5.1 presents a servlet that creates a table showing the values of all the
CGI variables other than
HTTP_XXX_YYY
, which are just the HTTP request
headers described in Chapter 4. Figure 5 1 shows the result for a typical
request.
Listing 5.1 ShowCGIVariables.java
package coreservlets;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
/** Creates a table showing the current value of each
* of the standard CGI variables.
*/
public class ShowCGIVariables extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String[][] variables =
{ { "AUTH_TYPE", request.getAuthType() },
{ "CONTENT_LENGTH",
String.valueOf(request.getContentLength()) },
{ "CONTENT_TYPE", request.getContentType() },
Second edition of this book: www.coreservlets.com; Sequel: www.moreservlets.com.
Servlet and JSP training courses by book's author: courses.coreservlets.com.
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved