KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mypackage > Hello


1 /*
2  * Copyright 1999,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
20 import java.io.PrintWriter JavaDoc;
21 import java.util.Enumeration JavaDoc;
22 import javax.servlet.ServletException JavaDoc;
23 import javax.servlet.http.HttpServlet JavaDoc;
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25 import javax.servlet.http.HttpServletResponse JavaDoc;
26
27
28 /**
29  * Simple servlet to validate that the Hello, World example can
30  * execute servlets. In the web application deployment descriptor,
31  * this servlet must be mapped to correspond to the link in the
32  * "index.html" file.
33  *
34  * @author Craig R. McClanahan <Craig.McClanahan@eng.sun.com>
35  */

36
37 public final class Hello extends HttpServlet JavaDoc {
38
39
40     /**
41      * Respond to a GET request for the content produced by
42      * this servlet.
43      *
44      * @param request The servlet request we are processing
45      * @param response The servlet response we are producing
46      *
47      * @exception IOException if an input/output error occurs
48      * @exception ServletException if a servlet error occurs
49      */

50     public void doGet(HttpServletRequest JavaDoc request,
51                       HttpServletResponse JavaDoc response)
52       throws IOException JavaDoc, ServletException JavaDoc {
53
54     response.setContentType("text/html");
55     PrintWriter JavaDoc writer = response.getWriter();
56
57     writer.println("<html>");
58     writer.println("<head>");
59     writer.println("<title>Sample Application Servlet Page</title>");
60     writer.println("</head>");
61     writer.println("<body bgcolor=white>");
62
63     writer.println("<table border=\"0\">");
64     writer.println("<tr>");
65     writer.println("<td>");
66     writer.println("<img SRC=\"images/tomcat.gif\">");
67     writer.println("</td>");
68     writer.println("<td>");
69     writer.println("<h1>Sample Application Servlet</h1>");
70     writer.println("This is the output of a servlet that is part of");
71     writer.println("the Hello, World application. It displays the");
72     writer.println("request headers from the request we are currently");
73     writer.println("processing.");
74     writer.println("</td>");
75     writer.println("</tr>");
76     writer.println("</table>");
77
78     writer.println("<table border=\"0\" width=\"100%\">");
79     Enumeration JavaDoc names = request.getHeaderNames();
80     while (names.hasMoreElements()) {
81         String JavaDoc name = (String JavaDoc) names.nextElement();
82         writer.println("<tr>");
83         writer.println(" <th align=\"right\">" + name + ":</th>");
84         writer.println(" <td>" + request.getHeader(name) + "</td>");
85         writer.println("</tr>");
86     }
87     writer.println("</table>");
88
89     writer.println("</body>");
90     writer.println("</html>");
91
92     }
93
94
95 }
96
Popular Tags