source: nutchez-0.1/tomcat/webapps/examples/WEB-INF/classes/RequestParamExample.java @ 186

Last change on this file since 186 was 66, checked in by waue, 16 years ago

NutchEz - an easy way to nutch

File size: 3.7 KB
RevLine 
[66]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/* $Id: RequestParamExample.java 500674 2007-01-27 23:15:00Z markt $
18 *
19 */
20
21import java.io.*;
22import java.util.*;
23import javax.servlet.*;
24import javax.servlet.http.*;
25
26import util.HTMLFilter;
27
28/**
29 * Example servlet showing request headers
30 *
31 * @author James Duncan Davidson <duncan@eng.sun.com>
32 */
33
34public 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        // img stuff not req'd for source code html showing
56
57  // all links relative
58
59        // XXX
60        // making these absolute till we work out the
61        // addition of a PathInfo issue
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}
Note: See TracBrowser for help on using the repository browser.