001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 /* $Id: HelloWorldExample.java 664175 2008-06-06 22:43:44Z djencks $ 018 * 019 */ 020 021 import java.io.IOException; 022 import java.io.PrintWriter; 023 import java.util.ResourceBundle; 024 025 import javax.servlet.ServletException; 026 import javax.servlet.http.HttpServlet; 027 import javax.servlet.http.HttpServletRequest; 028 import javax.servlet.http.HttpServletResponse; 029 030 /** 031 * The simplest possible servlet. 032 * 033 * @author James Duncan Davidson 034 */ 035 036 public class HelloWorldExample extends HttpServlet { 037 038 039 public void doGet(HttpServletRequest request, 040 HttpServletResponse response) 041 throws IOException, ServletException { 042 ResourceBundle rb = 043 ResourceBundle.getBundle("LocalStrings", request.getLocale()); 044 response.setContentType("text/html"); 045 PrintWriter out = response.getWriter(); 046 047 out.println("<html>"); 048 out.println("<head>"); 049 050 String title = rb.getString("helloworld.title"); 051 052 out.println("<title>" + title + "</title>"); 053 out.println("</head>"); 054 out.println("<body bgcolor=\"white\">"); 055 056 // note that all links are created to be relative. this 057 // ensures that we can move the web application that this 058 // servlet belongs to to a different place in the url 059 // tree and not have any harmful side effects. 060 061 // XXX 062 // making these absolute till we work out the 063 // addition of a PathInfo issue 064 065 out.println("<a href=\"../helloworld.html\">"); 066 out.println("<img src=\"../images/code.gif\" height=24 " + 067 "width=24 align=right border=0 alt=\"view code\"></a>"); 068 out.println("<a href=\"../index.html\">"); 069 out.println("<img src=\"../images/return.gif\" height=24 " + 070 "width=24 align=right border=0 alt=\"return\"></a>"); 071 out.println("<h1>" + title + "</h1>"); 072 out.println("</body>"); 073 out.println("</html>"); 074 } 075 } 076 077 078