1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 import java.io.*;
21 import java.text.*;
22 import java.util.*;
23 import javax.servlet.*;
24 import javax.servlet.http.*;
25
26 import util.HTMLFilter;
27
28 /**
29 * Example servlet showing request headers
30 *
31 * @author James Duncan Davidson <duncan@eng.sun.com>
32 */
33
34 public class RequestParamExample extends HttpServlet {
35
36
37 ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");
38
39 public void doGet(HttpServletRequest request,
40 HttpServletResponse response)
41 throws IOException, ServletException
42 {
43 response.setContentType("text/html");
44
45 PrintWriter out = response.getWriter();
46 out.println("<html>");
47 out.println("<body>");
48 out.println("<head>");
49
50 String title = rb.getString("requestparams.title");
51 out.println("<title>" + title + "</title>");
52 out.println("</head>");
53 out.println("<body bgcolor=\"white\">");
54
55
56
57
58
59
60
61
62
63 out.println("<a href=\"../reqparams.html\">");
64 out.println("<img src=\"../images/code.gif\" height=24 " +
65 "width=24 align=right border=0 alt=\"view code\"></a>");
66 out.println("<a href=\"../index.html\">");
67 out.println("<img src=\"../images/return.gif\" height=24 " +
68 "width=24 align=right border=0 alt=\"return\"></a>");
69
70 out.println("<h3>" + title + "</h3>");
71 String firstName = request.getParameter("firstname");
72 String lastName = request.getParameter("lastname");
73 out.println(rb.getString("requestparams.params-in-req") + "<br>");
74 if (firstName != null || lastName != null) {
75 out.println(rb.getString("requestparams.firstname"));
76 out.println(" = " + HTMLFilter.filter(firstName) + "<br>");
77 out.println(rb.getString("requestparams.lastname"));
78 out.println(" = " + HTMLFilter.filter(lastName));
79 } else {
80 out.println(rb.getString("requestparams.no-params"));
81 }
82 out.println("<P>");
83 out.print("<form action=\"");
84 out.print("RequestParamExample\" ");
85 out.println("method=POST>");
86 out.println(rb.getString("requestparams.firstname"));
87 out.println("<input type=text size=20 name=firstname>");
88 out.println("<br>");
89 out.println(rb.getString("requestparams.lastname"));
90 out.println("<input type=text size=20 name=lastname>");
91 out.println("<br>");
92 out.println("<input type=submit>");
93 out.println("</form>");
94
95 out.println("</body>");
96 out.println("</html>");
97 }
98
99 public void doPost(HttpServletRequest request,
100 HttpServletResponse response)
101 throws IOException, ServletException
102 {
103 doGet(request, response);
104 }
105
106 }