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