blob: a4c5c67763e7a8d30c42f72d9809e065fd8800de [file] [log] [blame]
Hongqing Liufd5ee812014-05-10 16:32:51 +08001/*
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
刘洪青6266f992017-05-15 21:21:03 +080018import java.io.IOException;
19import java.io.PrintWriter;
20import java.util.ResourceBundle;
21
22import javax.servlet.ServletException;
23import javax.servlet.http.HttpServlet;
24import javax.servlet.http.HttpServletRequest;
25import javax.servlet.http.HttpServletResponse;
Hongqing Liufd5ee812014-05-10 16:32:51 +080026
27import util.HTMLFilter;
28
29/**
30 * Example servlet showing request headers
31 *
32 * @author James Duncan Davidson <duncan@eng.sun.com>
33 */
34
35public class RequestParamExample extends HttpServlet {
36
刘洪青6266f992017-05-15 21:21:03 +080037 private static final long serialVersionUID = 1L;
Hongqing Liufd5ee812014-05-10 16:32:51 +080038
刘洪青6266f992017-05-15 21:21:03 +080039 private static final ResourceBundle RB = ResourceBundle.getBundle("LocalStrings");
40
41 @Override
Hongqing Liufd5ee812014-05-10 16:32:51 +080042 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
刘洪青6266f992017-05-15 21:21:03 +080052 String title = RB.getString("requestparams.title");
Hongqing Liufd5ee812014-05-10 16:32:51 +080053 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
刘洪青6266f992017-05-15 21:21:03 +080059 // all links relative
Hongqing Liufd5ee812014-05-10 16:32:51 +080060
61 // XXX
62 // making these absolute till we work out the
刘洪青6266f992017-05-15 21:21:03 +080063 // addition of a PathInfo issue
64
Hongqing Liufd5ee812014-05-10 16:32:51 +080065 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");
刘洪青6266f992017-05-15 21:21:03 +080075 out.println(RB.getString("requestparams.params-in-req") + "<br>");
Hongqing Liufd5ee812014-05-10 16:32:51 +080076 if (firstName != null || lastName != null) {
刘洪青6266f992017-05-15 21:21:03 +080077 out.println(RB.getString("requestparams.firstname"));
Hongqing Liufd5ee812014-05-10 16:32:51 +080078 out.println(" = " + HTMLFilter.filter(firstName) + "<br>");
刘洪青6266f992017-05-15 21:21:03 +080079 out.println(RB.getString("requestparams.lastname"));
Hongqing Liufd5ee812014-05-10 16:32:51 +080080 out.println(" = " + HTMLFilter.filter(lastName));
81 } else {
刘洪青6266f992017-05-15 21:21:03 +080082 out.println(RB.getString("requestparams.no-params"));
Hongqing Liufd5ee812014-05-10 16:32:51 +080083 }
84 out.println("<P>");
85 out.print("<form action=\"");
86 out.print("RequestParamExample\" ");
87 out.println("method=POST>");
刘洪青6266f992017-05-15 21:21:03 +080088 out.println(RB.getString("requestparams.firstname"));
Hongqing Liufd5ee812014-05-10 16:32:51 +080089 out.println("<input type=text size=20 name=firstname>");
90 out.println("<br>");
刘洪青6266f992017-05-15 21:21:03 +080091 out.println(RB.getString("requestparams.lastname"));
Hongqing Liufd5ee812014-05-10 16:32:51 +080092 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
刘洪青6266f992017-05-15 21:21:03 +0800101 @Override
Hongqing Liufd5ee812014-05-10 16:32:51 +0800102 public void doPost(HttpServletRequest request,
103 HttpServletResponse response)
104 throws IOException, ServletException
105 {
106 doGet(request, response);
107 }
108
109}