import javax.servlet.*; import javax.servlet.http.*; import java.io.*; // File: TestWebServlet.java // Listing 1 // /** * * This servlet responds with a simple thank-you note displaying
* the client's IP address. * * @author Chad (shod) Darby, darby@j-nine.com * @version 1.369, 13 Nov 97 * */ public class TestWebServlet extends HttpServlet { protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String clientIPAddress = request.getRemoteAddr(); String replyPage = null; // Build HTML page // replyPage = "
Thanks for calling the servlet from " + clientIPAddress; replyPage += ""; // Set the content type of response // response.setContentType("text/html"); // Get the output stream to the client response and send the page. // Note: The PrintWriter class is a new addition to Java 1.1 // PrintWriter out = new PrintWriter(response.getOutputStream()); out.println(replyPage); out.flush(); out.close(); } }