Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 771 | blopes | 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 | import java.io.IOException; |
||
| 18 | import java.io.PrintWriter; |
||
| 19 | import java.util.ResourceBundle; |
||
| 20 | |||
| 21 | import javax.servlet.ServletException; |
||
| 22 | import javax.servlet.http.HttpServlet; |
||
| 23 | import javax.servlet.http.HttpServletRequest; |
||
| 24 | import javax.servlet.http.HttpServletResponse; |
||
| 25 | |||
| 26 | import util.HTMLFilter; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Example servlet showing request headers |
||
| 30 | */ |
||
| 31 | public class RequestParamExample extends HttpServlet { |
||
| 32 | |||
| 33 | private static final long serialVersionUID = 1L; |
||
| 34 | |||
| 35 | @Override |
||
| 36 | public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { |
||
| 37 | ResourceBundle rb = ResourceBundle.getBundle("LocalStrings", request.getLocale()); |
||
| 38 | |||
| 39 | response.setContentType("text/html"); |
||
| 40 | response.setCharacterEncoding("UTF-8"); |
||
| 41 | |||
| 42 | PrintWriter out = response.getWriter(); |
||
| 43 | out.println("<!DOCTYPE html><html>"); |
||
| 44 | out.println("<head>"); |
||
| 45 | out.println("<meta charset=\"UTF-8\" />"); |
||
| 46 | |||
| 47 | String title = rb.getString("requestparams.title"); |
||
| 48 | out.println("<title>" + title + "</title>"); |
||
| 49 | out.println("</head>"); |
||
| 50 | out.println("<body bgcolor=\"white\">"); |
||
| 51 | |||
| 52 | out.println("<a href=\"../reqparams.html\">"); |
||
| 53 | out.println( |
||
| 54 | "<img src=\"../images/code.gif\" height=24 " + "width=24 align=right border=0 alt=\"view code\"></a>"); |
||
| 55 | out.println("<a href=\"../index.html\">"); |
||
| 56 | out.println( |
||
| 57 | "<img src=\"../images/return.gif\" height=24 " + "width=24 align=right border=0 alt=\"return\"></a>"); |
||
| 58 | |||
| 59 | out.println("<h3>" + title + "</h3>"); |
||
| 60 | String firstName = request.getParameter("firstname"); |
||
| 61 | String lastName = request.getParameter("lastname"); |
||
| 62 | out.println(rb.getString("requestparams.params-in-req") + "<br>"); |
||
| 63 | if (firstName != null || lastName != null) { |
||
| 64 | out.println(rb.getString("requestparams.firstname")); |
||
| 65 | out.println(" = " + HTMLFilter.filter(firstName) + "<br>"); |
||
| 66 | out.println(rb.getString("requestparams.lastname")); |
||
| 67 | out.println(" = " + HTMLFilter.filter(lastName)); |
||
| 68 | } else { |
||
| 69 | out.println(rb.getString("requestparams.no-params")); |
||
| 70 | } |
||
| 71 | out.println("<P>"); |
||
| 72 | out.print("<form action=\""); |
||
| 73 | out.print("RequestParamExample\" "); |
||
| 74 | out.println("method=POST>"); |
||
| 75 | out.println(rb.getString("requestparams.firstname")); |
||
| 76 | out.println("<input type=text size=20 name=firstname>"); |
||
| 77 | out.println("<br>"); |
||
| 78 | out.println(rb.getString("requestparams.lastname")); |
||
| 79 | out.println("<input type=text size=20 name=lastname>"); |
||
| 80 | out.println("<br>"); |
||
| 81 | out.println("<input type=submit>"); |
||
| 82 | out.println("</form>"); |
||
| 83 | |||
| 84 | out.println("</body>"); |
||
| 85 | out.println("</html>"); |
||
| 86 | } |
||
| 87 | |||
| 88 | @Override |
||
| 89 | public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { |
||
| 90 | doGet(request, response); |
||
| 91 | } |
||
| 92 | |||
| 93 | } |