/* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at * docs/licenses/cddl.txt * or http://www.opensource.org/licenses/cddl1.php. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at * docs/licenses/cddl.txt. If applicable, * add the following below this CDDL HEADER, with the fields enclosed * by brackets "[]" replaced with your own identifying information: * Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END * * * Copyright 2011-2016 UnboundID Corp. */ package com.unboundid.directory.sdk.examples; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * This class provides a simple servlet that merely displays a greeting when * it is invoked. */ public final class ExampleHelloServlet extends HttpServlet { /** * The serial version UID for this serializable class. */ private static final long serialVersionUID = -149961807238336777L; // The name to display in the greeting message. private volatile String name; /** * Creates a new instance of this servlet that will display the specified * name in a greeting message. * * @param name The name to use in the greeting. */ public ExampleHelloServlet(final String name) { this.name = name; } /** * Handles the necessary processing for an HTTP get request. * * @param request Information about the request received from the client. * @param response An object that may be used to define the response to send * to the client. * * @throws IOException If a problem is encountered while attempting to * communicate with the client. */ @Override() public void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException { response.setStatus(HttpServletResponse.SC_OK); response.setContentType("text/html"); final PrintWriter w = response.getWriter(); w.println("<html>"); w.println(" <head>"); w.println(" <title>Hello, " + name + "!</title>"); w.println(" </head>"); w.println(" <body>"); w.println(" <h1>Hello, " + name + "!</h1>"); w.println(" </body>"); w.println("</html>"); } /** * Sets the name that should be used for the greeting. * * @param name The name that should be used for the greeting. */ public void setName(final String name) { this.name = name; } }