/* * @(#)Properties.java * * Copyright (c) 1998 Karl Moss. All Rights Reserved. * * You may study, use, modify, and distribute this software for any * purpose provided that this copyright notice appears in all copies. * * This software is provided WITHOUT WARRANTY either expressed or * implied. * * @author Karl Moss * @version 1.0 * @date 16Feb98 * */ package javaservlets.samples; import javax.servlet.*; import javax.servlet.http.*; /** *

This is a simple servlet that will echo information about * the client and also provide a listing of all of the * system properties on the server. */ public class Properties extends HttpServlet { /** *

Performs the HTTP POST operation * * @param req The request from the client * @param resp The response from the servlet */ public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, java.io.IOException { // Set the content type of the response resp.setContentType("text/html"); // Create a PrintWriter to write the response java.io.PrintWriter out = new java.io.PrintWriter(resp.getOutputStream()); // Print the HTML header out.println(""); out.println(""); out.println("Java Servlets Sample - Properties"); out.println(""); out.println("

"); out.println("Information About You

"); out.println("
"); // Create a table with information about the client out.println("
"); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); java.util.Enumeration enum = req.getParameterNames(); while (enum.hasMoreElements()) { String name = (String) enum.nextElement(); out.println(""); out.println(""); out.println(""); out.println(""); } out.println("
Method" + req.getMethod() + "
User" + req.getRemoteUser() + "
Client" + req.getRemoteHost() + "
Protocol" + req.getProtocol() + "
Parameter '" + name + "'" + req.getParameter(name) + "



"); // Create a table with information about the server out.println("

"); out.println("Server Properties

"); out.println("
"); out.println("
"); java.util.Properties props = System.getProperties(); enum = props.propertyNames(); while (enum.hasMoreElements()) { String name = (String) enum.nextElement(); out.println(""); out.println(""); out.println(""); out.println(""); } out.println("
" + name + "" + props.getProperty(name) + "
"); // Wrap up out.println(""); out.flush(); } /** *

Initialize the servlet. This is called once when the * servlet is loaded. It is guaranteed to complete before any * requests are made to the servlet * * @param cfg Servlet configuration information */ public void init(ServletConfig cfg) throws ServletException { super.init(cfg); } /** *

Destroy the servlet. This is called once when the servlet * is unloaded. */ public void destroy() { super.destroy(); } }