KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > HelloWorldExample


1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */

17 /* $Id: HelloWorldExample.java 476311 2006-11-17 20:55:33Z vamsic007 $
18  *
19  */

20
21 import java.io.*;
22 import java.text.*;
23 import java.util.*;
24 import javax.servlet.*;
25 import javax.servlet.http.*;
26
27 /**
28  * The simplest possible servlet.
29  *
30  * @author James Duncan Davidson
31  */

32
33 public class HelloWorldExample extends HttpServlet {
34
35
36     public void doGet(HttpServletRequest request,
37                       HttpServletResponse response)
38         throws IOException, ServletException
39     {
40         ResourceBundle rb =
41             ResourceBundle.getBundle("LocalStrings",request.getLocale());
42         response.setContentType("text/html");
43         PrintWriter out = response.getWriter();
44
45         out.println("<html>");
46         out.println("<head>");
47
48         String JavaDoc title = rb.getString("helloworld.title");
49
50         out.println("<title>" + title + "</title>");
51         out.println("</head>");
52         out.println("<body bgcolor=\"white\">");
53
54     // note that all links are created to be relative. this
55
// ensures that we can move the web application that this
56
// servlet belongs to to a different place in the url
57
// tree and not have any harmful side effects.
58

59         // XXX
60
// making these absolute till we work out the
61
// addition of a PathInfo issue
62

63         out.println("<a HREF=\"../helloworld.html\">");
64         out.println("<img SRC=\"../images/code.gif\" height=24 " +
65                     "width=24 align=right border=0 alt=\"view code\"></a>");
66         out.println("<a HREF=\"../index.html\">");
67         out.println("<img SRC=\"../images/return.gif\" height=24 " +
68                     "width=24 align=right border=0 alt=\"return\"></a>");
69         out.println("<h1>" + title + "</h1>");
70         out.println("</body>");
71         out.println("</html>");
72     }
73 }
74
75
76
77
Popular Tags