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 | <html>
|
| 18 | <head>
|
| 19 | <title>Untitled Document</title>
|
| 20 | <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
| 21 | </head>
|
| 22 |
|
| 23 | <body bgcolor="#FFFFFF">
|
| 24 | <p><font color="#0000FF"><a href="servlet/RequestInfoExample"><img src="images/execute.gif" align="right" border="0"></a><a href="index.html"><img src="images/return.gif" width="24" height="24" align="right" border="0"></a></font></p>
|
| 25 | <h3>Source Code for Request Info Example<font color="#0000FF"><br>
|
| 26 | </font> </h3>
|
| 27 | <font color="#0000FF"></font>
|
| 28 | <pre><font color="#0000FF">import</font> java.io.*;
|
| 29 | <font color="#0000FF">import</font> javax.servlet.*;
|
| 30 | <font color="#0000FF">import</font> javax.servlet.http.*;
|
| 31 |
|
| 32 | <font color="#0000FF">public class</font> RequestInfo <font color="#0000FF">extends</font> HttpServlet {
|
| 33 |
|
| 34 | <font color="#0000FF">public void</font> doGet(HttpServletRequest request, HttpServletResponse response)
|
| 35 | <font color="#0000FF">throws</font> IOException, ServletException
|
| 36 | {
|
| 37 | response.setContentType("<font color="#009900">text/html</font>");
|
| 38 | PrintWriter out = response.getWriter();
|
| 39 | out.println("<font color="#009900"><html></font>");
|
| 40 | out.println("<font color="#009900"><body></font>");
|
| 41 | out.println("<font color="#009900"><head></font>");
|
| 42 | out.println("<font color="#009900"><title>Request Information Example</title></font>");
|
| 43 | out.println("<font color="#009900"></head></font>");
|
| 44 | out.println("<font color="#009900"><body></font>");
|
| 45 | out.println("<font color="#009900"><h3>Request Information Example</h3></font>");
|
| 46 | out.println("<font color="#009900">Method: </font>" + request.getMethod());
|
| 47 | out.println("<font color="#009900">Request URI: </font>" + request.getRequestURI());
|
| 48 | out.println("<font color="#009900">Protocol: </font>" + request.getProtocol());
|
| 49 | out.println("<font color="#009900">PathInfo: </font>" + request.getPathInfo());
|
| 50 | out.println("<font color="#009900">Remote Address: </font>" + request.getRemoteAddr());
|
| 51 | out.println("<font color="#009900"></body></font>");
|
| 52 | out.println("<font color="#009900"></html></font>");
|
| 53 | }
|
| 54 |
|
| 55 | <font color="#FF0000"> /**
|
| 56 | * We are going to perform the same operations for POST requests
|
| 57 | * as for GET methods, so this method just sends the request to
|
| 58 | * the doGet method.
|
| 59 | */</font>
|
| 60 |
|
| 61 | <font color="#0000FF">public void</font> doPost(HttpServletRequest request, HttpServletResponse response)
|
| 62 | <font color="#0000FF">throws</font> IOException, ServletException
|
| 63 | {
|
| 64 | doGet(request, response);
|
| 65 | }
|
| 66 | }</pre>
|
| 67 | </body>
|
| 68 | </html>
|