blob: 039c222be76220ddb750101549d7e7df0ca95649 [file] [log] [blame]
Michael E. Rodriguezd8af66f2005-12-08 20:55:55 +00001/*
2 * Copyright 1999,2005 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package javax.servlet;
18
19import java.io.BufferedReader;
20import java.io.IOException;
21import java.util.Enumeration;
22
23
24
25/**
26 * Defines an object to provide client request information to a servlet. The
27 * servlet container creates a <code>ServletRequest</code> object and passes
28 * it as an argument to the servlet's <code>service</code> method.
29 *
30 * <p>A <code>ServletRequest</code> object provides data including
31 * parameter name and values, attributes, and an input stream.
32 * Interfaces that extend <code>ServletRequest</code> can provide
33 * additional protocol-specific data (for example, HTTP data is
34 * provided by {@link javax.servlet.http.HttpServletRequest}.
35 *
36 * @author Various
37 * @version $Version$
38 *
39 * @see javax.servlet.http.HttpServletRequest
40 *
41 */
42
43public interface ServletRequest {
44
45
46
47
48 /**
49 *
50 * Returns the value of the named attribute as an <code>Object</code>,
51 * or <code>null</code> if no attribute of the given name exists.
52 *
53 * <p> Attributes can be set two ways. The servlet container may set
54 * attributes to make available custom information about a request.
55 * For example, for requests made using HTTPS, the attribute
56 * <code>javax.servlet.request.X509Certificate</code> can be used to
57 * retrieve information on the certificate of the client. Attributes
58 * can also be set programatically using
59 * {@link ServletRequest#setAttribute}. This allows information to be
60 * embedded into a request before a {@link RequestDispatcher} call.
61 *
62 * <p>Attribute names should follow the same conventions as package
63 * names. This specification reserves names matching <code>java.*</code>,
64 * <code>javax.*</code>, and <code>sun.*</code>.
65 *
66 * @param name a <code>String</code> specifying the name of
67 * the attribute
68 *
69 * @return an <code>Object</code> containing the value
70 * of the attribute, or <code>null</code> if
71 * the attribute does not exist
72 *
73 */
74
75 public Object getAttribute(String name);
76
77
78
79 /**
80 * Returns an <code>Enumeration</code> containing the
81 * names of the attributes available to this request.
82 * This method returns an empty <code>Enumeration</code>
83 * if the request has no attributes available to it.
84 *
85 *
86 * @return an <code>Enumeration</code> of strings
87 * containing the names
88 * of the request's attributes
89 *
90 */
91
92 public Enumeration getAttributeNames();
93
94
95
96
97 /**
98 * Returns the name of the character encoding used in the body of this
99 * request. This method returns <code>null</code> if the request
100 * does not specify a character encoding
101 *
102 *
103 * @return a <code>String</code> containing the name of
104 * the chararacter encoding, or <code>null</code>
105 * if the request does not specify a character encoding
106 *
107 */
108
109 public String getCharacterEncoding();
110
111
112
113 /**
114 * Returns the length, in bytes, of the request body
115 * and made available by the input stream, or -1 if the
116 * length is not known. For HTTP servlets, same as the value
117 * of the CGI variable CONTENT_LENGTH.
118 *
119 * @return an integer containing the length of the
120 * request body or -1 if the length is not known
121 *
122 */
123
124 public int getContentLength();
125
126
127
128
129 /**
130 * Returns the MIME type of the body of the request, or
131 * <code>null</code> if the type is not known. For HTTP servlets,
132 * same as the value of the CGI variable CONTENT_TYPE.
133 *
134 * @return a <code>String</code> containing the name
135 * of the MIME type of
136 * the request, or null if the type is not known
137 *
138 */
139
140 public String getContentType();
141
142
143
144
145 /**
146 * Retrieves the body of the request as binary data using
147 * a {@link ServletInputStream}. Either this method or
148 * {@link #getReader} may be called to read the body, not both.
149 *
150 * @return a {@link ServletInputStream} object containing
151 * the body of the request
152 *
153 * @exception IllegalStateException if the {@link #getReader} method
154 * has already been called for this request
155 *
156 * @exception IOException if an input or output exception occurred
157 *
158 */
159
160 public ServletInputStream getInputStream() throws IOException;
161
162
163
164
165 /**
166 * Returns the value of a request parameter as a <code>String</code>,
167 * or <code>null</code> if the parameter does not exist. Request parameters
168 * are extra information sent with the request. For HTTP servlets,
169 * parameters are contained in the query string or posted form data.
170 *
171 * <p>You should only use this method when you are sure the
172 * parameter has only one value. If the parameter might have
173 * more than one value, use {@link #getParameterValues}.
174 *
175 * <p>If you use this method with a multivalued
176 * parameter, the value returned is equal to the first value
177 * in the array returned by <code>getParameterValues</code>.
178 *
179 * <p>If the parameter data was sent in the request body, such as occurs
180 * with an HTTP POST request, then reading the body directly via {@link
181 * #getInputStream} or {@link #getReader} can interfere
182 * with the execution of this method.
183 *
184 * @param name a <code>String</code> specifying the
185 * name of the parameter
186 *
187 * @return a <code>String</code> representing the
188 * single value of the parameter
189 *
190 * @see #getParameterValues
191 *
192 */
193
194 public String getParameter(String name);
195
196
197
198
199 /**
200 *
201 * Returns an <code>Enumeration</code> of <code>String</code>
202 * objects containing the names of the parameters contained
203 * in this request. If the request has
204 * no parameters, the method returns an
205 * empty <code>Enumeration</code>.
206 *
207 * @return an <code>Enumeration</code> of <code>String</code>
208 * objects, each <code>String</code> containing
209 * the name of a request parameter; or an
210 * empty <code>Enumeration</code> if the
211 * request has no parameters
212 *
213 */
214
215 public Enumeration getParameterNames();
216
217
218
219
220 /**
221 * Returns an array of <code>String</code> objects containing
222 * all of the values the given request parameter has, or
223 * <code>null</code> if the parameter does not exist.
224 *
225 * <p>If the parameter has a single value, the array has a length
226 * of 1.
227 *
228 * @param name a <code>String</code> containing the name of
229 * the parameter whose value is requested
230 *
231 * @return an array of <code>String</code> objects
232 * containing the parameter's values
233 *
234 * @see #getParameter
235 *
236 */
237
238 public String[] getParameterValues(String name);
239
240 /**
241 * Returns the name and version of the protocol the request uses
242 * in the form <i>protocol/majorVersion.minorVersion</i>, for
243 * example, HTTP/1.1. For HTTP servlets, the value
244 * returned is the same as the value of the CGI variable
245 * <code>SERVER_PROTOCOL</code>.
246 *
247 * @return a <code>String</code> containing the protocol
248 * name and version number
249 *
250 */
251
252 public String getProtocol();
253
254
255
256
257 /**
258 * Returns the name of the scheme used to make this request,
259 * for example,
260 * <code>http</code>, <code>https</code>, or <code>ftp</code>.
261 * Different schemes have different rules for constructing URLs,
262 * as noted in RFC 1738.
263 *
264 * @return a <code>String</code> containing the name
265 * of the scheme used to make this request
266 *
267 */
268
269 public String getScheme();
270
271
272
273
274 /**
275 * Returns the host name of the server that received the request.
276 * For HTTP servlets, same as the value of the CGI variable
277 * <code>SERVER_NAME</code>.
278 *
279 * @return a <code>String</code> containing the name
280 * of the server to which the request was sent
281 */
282
283 public String getServerName();
284
285
286
287
288 /**
289 * Returns the port number on which this request was received.
290 * For HTTP servlets, same as the value of the CGI variable
291 * <code>SERVER_PORT</code>.
292 *
293 * @return an integer specifying the port number
294 *
295 */
296
297 public int getServerPort();
298
299
300
301 /**
302 * Retrieves the body of the request as character data using
303 * a <code>BufferedReader</code>. The reader translates the character
304 * data according to the character encoding used on the body.
305 * Either this method or {@link #getInputStream} may be called to read the
306 * body, not both.
307 *
308 *
309 * @return a <code>BufferedReader</code>
310 * containing the body of the request
311 *
312 * @exception IllegalStateException if {@link #getInputStream} method
313 * has been called on this request
314 *
315 * @exception IOException if an input or output exception occurred
316 *
317 * @see #getInputStream
318 *
319 */
320
321 public BufferedReader getReader() throws IOException;
322
323
324
325
326 /**
327 * Returns the Internet Protocol (IP) address of the client
328 * that sent the request. For HTTP servlets, same as the value of the
329 * CGI variable <code>REMOTE_ADDR</code>.
330 *
331 * @return a <code>String</code> containing the
332 * IP address of the client that sent the request
333 *
334 */
335
336 public String getRemoteAddr();
337
338
339
340
341 /**
342 * Returns the fully qualified name of the client that sent the
343 * request. If the engine cannot or chooses not to resolve the hostname
344 * (to improve performance), this method returns the dotted-string form of
345 * the IP address. For HTTP servlets, same as the value of the CGI variable
346 * <code>REMOTE_HOST</code>.
347 *
348 * @return a <code>String</code> containing the fully
349 * qualified name of the client
350 *
351 */
352
353 public String getRemoteHost();
354
355
356
357
358 /**
359 *
360 * Stores an attribute in this request.
361 * Attributes are reset between requests. This method is most
362 * often used in conjunction with {@link RequestDispatcher}.
363 *
364 * <p>Attribute names should follow the same conventions as
365 * package names. Names beginning with <code>java.*</code>,
366 * <code>javax.*</code>, and <code>com.sun.*</code>, are
367 * reserved for use by Sun Microsystems.
368 *
369 *
370 * @param name a <code>String</code> specifying
371 * the name of the attribute
372 *
373 * @param o the <code>Object</code> to be stored
374 *
375 */
376
377 public void setAttribute(String name, Object o);
378
379
380
381
382 /**
383 *
384 * @deprecated As of Version 2.1 of the Java Servlet API,
385 * use {@link ServletContext#getRealPath} instead.
386 *
387 */
388
389 public String getRealPath(String path);
390
391
392}
393