01: /*
02: * Copyright 1999,2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package mypackage;
18:
19: import java.io.IOException;
20: import java.io.PrintWriter;
21: import java.util.Enumeration;
22: import javax.servlet.ServletException;
23: import javax.servlet.http.HttpServlet;
24: import javax.servlet.http.HttpServletRequest;
25: import javax.servlet.http.HttpServletResponse;
26:
27: /**
28: * Simple servlet to validate that the Hello, World example can
29: * execute servlets. In the web application deployment descriptor,
30: * this servlet must be mapped to correspond to the link in the
31: * "index.html" file.
32: *
33: * @author Craig R. McClanahan <Craig.McClanahan@eng.sun.com>
34: */
35:
36: public final class Hello extends HttpServlet {
37:
38: /**
39: * Respond to a GET request for the content produced by
40: * this servlet.
41: *
42: * @param request The servlet request we are processing
43: * @param response The servlet response we are producing
44: *
45: * @exception IOException if an input/output error occurs
46: * @exception ServletException if a servlet error occurs
47: */
48: public void doGet(HttpServletRequest request,
49: HttpServletResponse response) throws IOException,
50: ServletException {
51:
52: response.setContentType("text/html");
53: PrintWriter writer = response.getWriter();
54:
55: writer.println("<html>");
56: writer.println("<head>");
57: writer
58: .println("<title>Sample Application Servlet Page</title>");
59: writer.println("</head>");
60: writer.println("<body bgcolor=white>");
61:
62: writer.println("<table border=\"0\">");
63: writer.println("<tr>");
64: writer.println("<td>");
65: writer.println("<img src=\"images/tomcat.gif\">");
66: writer.println("</td>");
67: writer.println("<td>");
68: writer.println("<h1>Sample Application Servlet</h1>");
69: writer
70: .println("This is the output of a servlet that is part of");
71: writer
72: .println("the Hello, World application. It displays the");
73: writer
74: .println("request headers from the request we are currently");
75: writer.println("processing.");
76: writer.println("</td>");
77: writer.println("</tr>");
78: writer.println("</table>");
79:
80: writer.println("<table border=\"0\" width=\"100%\">");
81: Enumeration names = request.getHeaderNames();
82: while (names.hasMoreElements()) {
83: String name = (String) names.nextElement();
84: writer.println("<tr>");
85: writer.println(" <th align=\"right\">" + name + ":</th>");
86: writer
87: .println(" <td>" + request.getHeader(name)
88: + "</td>");
89: writer.println("</tr>");
90: }
91: writer.println("</table>");
92:
93: writer.println("</body>");
94: writer.println("</html>");
95:
96: }
97:
98: }
|