Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 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 |
|
| 18 | import java.io.*;
|
| 19 | import java.util.*;
|
| 20 | import javax.servlet.*;
|
| 21 | import javax.servlet.http.*;
|
| 22 |
|
| 23 | import util.HTMLFilter;
|
| 24 |
|
| 25 | /**
|
| 26 | * Example servlet showing request headers
|
| 27 | *
|
| 28 | * @author James Duncan Davidson <duncan@eng.sun.com>
|
| 29 | */
|
| 30 |
|
| 31 | public class RequestParamExample extends HttpServlet {
|
| 32 |
|
| 33 |
|
| 34 | ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");
|
| 35 |
|
| 36 | public void doGet(HttpServletRequest request,
|
| 37 | HttpServletResponse response)
|
| 38 | throws IOException, ServletException
|
| 39 | {
|
| 40 | response.setContentType("text/html");
|
| 41 |
|
| 42 | PrintWriter out = response.getWriter();
|
| 43 | out.println("<html>");
|
| 44 | out.println("<head>");
|
| 45 |
|
| 46 | String title = rb.getString("requestparams.title");
|
| 47 | out.println("<title>" + title + "</title>");
|
| 48 | out.println("</head>");
|
| 49 | out.println("<body bgcolor=\"white\">");
|
| 50 |
|
| 51 | // img stuff not req'd for source code html showing
|
| 52 |
|
| 53 | // all links relative
|
| 54 |
|
| 55 | // XXX
|
| 56 | // making these absolute till we work out the
|
| 57 | // addition of a PathInfo issue
|
| 58 |
|
| 59 | out.println("<a href=\"../reqparams.html\">");
|
| 60 | out.println("<img src=\"../images/code.gif\" height=24 " +
|
| 61 | "width=24 align=right border=0 alt=\"view code\"></a>");
|
| 62 | out.println("<a href=\"../index.html\">");
|
| 63 | out.println("<img src=\"../images/return.gif\" height=24 " +
|
| 64 | "width=24 align=right border=0 alt=\"return\"></a>");
|
| 65 |
|
| 66 | out.println("<h3>" + title + "</h3>");
|
| 67 | String firstName = request.getParameter("firstname");
|
| 68 | String lastName = request.getParameter("lastname");
|
| 69 | out.println(rb.getString("requestparams.params-in-req") + "<br>");
|
| 70 | if (firstName != null || lastName != null) {
|
| 71 | out.println(rb.getString("requestparams.firstname"));
|
| 72 | out.println(" = " + HTMLFilter.filter(firstName) + "<br>");
|
| 73 | out.println(rb.getString("requestparams.lastname"));
|
| 74 | out.println(" = " + HTMLFilter.filter(lastName));
|
| 75 | } else {
|
| 76 | out.println(rb.getString("requestparams.no-params"));
|
| 77 | }
|
| 78 | out.println("<P>");
|
| 79 | out.print("<form action=\"");
|
| 80 | out.print("RequestParamExample\" ");
|
| 81 | out.println("method=POST>");
|
| 82 | out.println(rb.getString("requestparams.firstname"));
|
| 83 | out.println("<input type=text size=20 name=firstname>");
|
| 84 | out.println("<br>");
|
| 85 | out.println(rb.getString("requestparams.lastname"));
|
| 86 | out.println("<input type=text size=20 name=lastname>");
|
| 87 | out.println("<br>");
|
| 88 | out.println("<input type=submit>");
|
| 89 | out.println("</form>");
|
| 90 |
|
| 91 | out.println("</body>");
|
| 92 | out.println("</html>");
|
| 93 | }
|
| 94 |
|
| 95 | public void doPost(HttpServletRequest request,
|
| 96 | HttpServletResponse response)
|
| 97 | throws IOException, ServletException
|
| 98 | {
|
| 99 | doGet(request, response);
|
| 100 | }
|
| 101 |
|
| 102 | }
|