View Javadoc

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