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: RequestParamExample.java 514091 2007-03-03 06:26:39Z jdillon $
018 *
019 */
020
021 import java.io.*;
022 import java.util.*;
023 import javax.servlet.*;
024 import javax.servlet.http.*;
025
026 import util.HTMLFilter;
027
028 /**
029 * Example servlet showing request headers
030 *
031 * @author James Duncan Davidson <duncan@eng.sun.com>
032 */
033
034 public class RequestParamExample extends HttpServlet {
035
036
037 ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");
038
039 public void doGet(HttpServletRequest request,
040 HttpServletResponse response)
041 throws IOException, ServletException
042 {
043 response.setContentType("text/html");
044
045 PrintWriter out = response.getWriter();
046 out.println("<html>");
047 out.println("<body>");
048 out.println("<head>");
049
050 String title = rb.getString("requestparams.title");
051 out.println("<title>" + title + "</title>");
052 out.println("</head>");
053 out.println("<body bgcolor=\"white\">");
054
055 // img stuff not req'd for source code html showing
056
057 // all links relative
058
059 // XXX
060 // making these absolute till we work out the
061 // addition of a PathInfo issue
062
063 out.println("<a href=\"../reqparams.html\">");
064 out.println("<img src=\"../images/code.gif\" height=24 " +
065 "width=24 align=right border=0 alt=\"view code\"></a>");
066 out.println("<a href=\"../index.html\">");
067 out.println("<img src=\"../images/return.gif\" height=24 " +
068 "width=24 align=right border=0 alt=\"return\"></a>");
069
070 out.println("<h3>" + title + "</h3>");
071 String firstName = request.getParameter("firstname");
072 String lastName = request.getParameter("lastname");
073 out.println(rb.getString("requestparams.params-in-req") + "<br>");
074 if (firstName != null || lastName != null) {
075 out.println(rb.getString("requestparams.firstname"));
076 out.println(" = " + HTMLFilter.filter(firstName) + "<br>");
077 out.println(rb.getString("requestparams.lastname"));
078 out.println(" = " + HTMLFilter.filter(lastName));
079 } else {
080 out.println(rb.getString("requestparams.no-params"));
081 }
082 out.println("<P>");
083 out.print("<form action=\"");
084 out.print("RequestParamExample\" ");
085 out.println("method=POST>");
086 out.println(rb.getString("requestparams.firstname"));
087 out.println("<input type=text size=20 name=firstname>");
088 out.println("<br>");
089 out.println(rb.getString("requestparams.lastname"));
090 out.println("<input type=text size=20 name=lastname>");
091 out.println("<br>");
092 out.println("<input type=submit>");
093 out.println("</form>");
094
095 out.println("</body>");
096 out.println("</html>");
097 }
098
099 public void doPost(HttpServletRequest request,
100 HttpServletResponse response)
101 throws IOException, ServletException
102 {
103 doGet(request, response);
104 }
105
106 }