View Javadoc

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 664175 2008-06-06 22:43:44Z djencks $
18   *
19   */
20  
21  import java.io.IOException;
22  import java.io.PrintWriter;
23  import java.util.ResourceBundle;
24  
25  import javax.servlet.ServletException;
26  import javax.servlet.http.HttpServlet;
27  import javax.servlet.http.HttpServletRequest;
28  import javax.servlet.http.HttpServletResponse;
29  
30  /**
31   * The simplest possible servlet.
32   *
33   * @author James Duncan Davidson
34   */
35  
36  public class HelloWorldExample extends HttpServlet {
37  
38  
39      public void doGet(HttpServletRequest request,
40                        HttpServletResponse response)
41              throws IOException, ServletException {
42          ResourceBundle rb =
43                  ResourceBundle.getBundle("LocalStrings", request.getLocale());
44          response.setContentType("text/html");
45          PrintWriter out = response.getWriter();
46  
47          out.println("<html>");
48          out.println("<head>");
49  
50          String title = rb.getString("helloworld.title");
51  
52          out.println("<title>" + title + "</title>");
53          out.println("</head>");
54          out.println("<body bgcolor=\"white\">");
55  
56          // note that all links are created to be relative. this
57          // ensures that we can move the web application that this
58          // servlet belongs to to a different place in the url
59          // tree and not have any harmful side effects.
60  
61          // XXX
62          // making these absolute till we work out the
63          // addition of a PathInfo issue
64  
65          out.println("<a href=\"../helloworld.html\">");
66          out.println("<img src=\"../images/code.gif\" height=24 " +
67                  "width=24 align=right border=0 alt=\"view code\"></a>");
68          out.println("<a href=\"../index.html\">");
69          out.println("<img src=\"../images/return.gif\" height=24 " +
70                  "width=24 align=right border=0 alt=\"return\"></a>");
71          out.println("<h1>" + title + "</h1>");
72          out.println("</body>");
73          out.println("</html>");
74      }
75  }
76  
77  
78