1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. * Copyright (c) 1999 The Apache Software Foundation. All rights
  5. * reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. *
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. *
  19. * 3. The end-user documentation included with the redistribution, if
  20. * any, must include the following acknowlegement:
  21. * "This product includes software developed by the
  22. * Apache Software Foundation (http://www.apache.org/)."
  23. * Alternately, this acknowlegement may appear in the software itself,
  24. * if and wherever such third-party acknowlegements normally appear.
  25. *
  26. * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
  27. * Foundation" must not be used to endorse or promote products derived
  28. * from this software without prior written permission. For written
  29. * permission, please contact apache@apache.org.
  30. *
  31. * 5. Products derived from this software may not be called "Apache"
  32. * nor may "Apache" appear in their names without prior written
  33. * permission of the Apache Group.
  34. *
  35. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46. * SUCH DAMAGE.
  47. * ====================================================================
  48. *
  49. * This software consists of voluntary contributions made by many
  50. * individuals on behalf of the Apache Software Foundation. For more
  51. * information on the Apache Software Foundation, please see
  52. * <http://www.apache.org/>.
  53. *
  54. * ====================================================================
  55. *
  56. * This source code implements specifications defined by the Java
  57. * Community Process. In order to remain compliant with the specification
  58. * DO NOT add / change / or delete method signatures!
  59. */
  60. package javax.servlet;
  61. import java.io.BufferedReader;
  62. import java.io.IOException;
  63. import java.io.UnsupportedEncodingException;
  64. import java.util.Enumeration;
  65. import java.util.Locale;
  66. import java.util.Map;
  67. /**
  68. * Defines an object to provide client request information to a servlet. The
  69. * servlet container creates a <code>ServletRequest</code> object and passes
  70. * it as an argument to the servlet's <code>service</code> method.
  71. *
  72. * <p>A <code>ServletRequest</code> object provides data including
  73. * parameter name and values, attributes, and an input stream.
  74. * Interfaces that extend <code>ServletRequest</code> can provide
  75. * additional protocol-specific data (for example, HTTP data is
  76. * provided by {@link javax.servlet.http.HttpServletRequest}.
  77. *
  78. * @author Various
  79. * @version $Version$
  80. *
  81. * @see javax.servlet.http.HttpServletRequest
  82. *
  83. */
  84. public interface ServletRequest {
  85. /**
  86. *
  87. * Returns the value of the named attribute as an <code>Object</code>,
  88. * or <code>null</code> if no attribute of the given name exists.
  89. *
  90. * <p> Attributes can be set two ways. The servlet container may set
  91. * attributes to make available custom information about a request.
  92. * For example, for requests made using HTTPS, the attribute
  93. * <code>javax.servlet.request.X509Certificate</code> can be used to
  94. * retrieve information on the certificate of the client. Attributes
  95. * can also be set programatically using
  96. * {@link ServletRequest#setAttribute}. This allows information to be
  97. * embedded into a request before a {@link RequestDispatcher} call.
  98. *
  99. * <p>Attribute names should follow the same conventions as package
  100. * names. This specification reserves names matching <code>java.*</code>,
  101. * <code>javax.*</code>, and <code>sun.*</code>.
  102. *
  103. * @param name a <code>String</code> specifying the name of
  104. * the attribute
  105. *
  106. * @return an <code>Object</code> containing the value
  107. * of the attribute, or <code>null</code> if
  108. * the attribute does not exist
  109. *
  110. */
  111. public Object getAttribute(String name);
  112. /**
  113. * Returns an <code>Enumeration</code> containing the
  114. * names of the attributes available to this request.
  115. * This method returns an empty <code>Enumeration</code>
  116. * if the request has no attributes available to it.
  117. *
  118. *
  119. * @return an <code>Enumeration</code> of strings
  120. * containing the names
  121. * of the request's attributes
  122. *
  123. */
  124. public Enumeration getAttributeNames();
  125. /**
  126. * Returns the name of the character encoding used in the body of this
  127. * request. This method returns <code>null</code> if the request
  128. * does not specify a character encoding
  129. *
  130. *
  131. * @return a <code>String</code> containing the name of
  132. * the chararacter encoding, or <code>null</code>
  133. * if the request does not specify a character encoding
  134. *
  135. */
  136. public String getCharacterEncoding();
  137. /**
  138. * Overrides the name of the character encoding used in the body of this
  139. * request. This method must be called prior to reading request parameters
  140. * or reading input using getReader().
  141. *
  142. *
  143. * @param a <code>String</code> containing the name of
  144. * the chararacter encoding.
  145. * @throws java.io.UnsupportedEncodingException if this is not a valid encoding
  146. */
  147. public void setCharacterEncoding(String env) throws java.io.UnsupportedEncodingException;
  148. /**
  149. * Returns the length, in bytes, of the request body
  150. * and made available by the input stream, or -1 if the
  151. * length is not known. For HTTP servlets, same as the value
  152. * of the CGI variable CONTENT_LENGTH.
  153. *
  154. * @return an integer containing the length of the
  155. * request body or -1 if the length is not known
  156. *
  157. */
  158. public int getContentLength();
  159. /**
  160. * Returns the MIME type of the body of the request, or
  161. * <code>null</code> if the type is not known. For HTTP servlets,
  162. * same as the value of the CGI variable CONTENT_TYPE.
  163. *
  164. * @return a <code>String</code> containing the name
  165. * of the MIME type of
  166. * the request, or null if the type is not known
  167. *
  168. */
  169. public String getContentType();
  170. /**
  171. * Retrieves the body of the request as binary data using
  172. * a {@link ServletInputStream}. Either this method or
  173. * {@link #getReader} may be called to read the body, not both.
  174. *
  175. * @return a {@link ServletInputStream} object containing
  176. * the body of the request
  177. *
  178. * @exception IllegalStateException if the {@link #getReader} method
  179. * has already been called for this request
  180. *
  181. * @exception IOException if an input or output exception occurred
  182. *
  183. */
  184. public ServletInputStream getInputStream() throws IOException;
  185. /**
  186. * Returns the value of a request parameter as a <code>String</code>,
  187. * or <code>null</code> if the parameter does not exist. Request parameters
  188. * are extra information sent with the request. For HTTP servlets,
  189. * parameters are contained in the query string or posted form data.
  190. *
  191. * <p>You should only use this method when you are sure the
  192. * parameter has only one value. If the parameter might have
  193. * more than one value, use {@link #getParameterValues}.
  194. *
  195. * <p>If you use this method with a multivalued
  196. * parameter, the value returned is equal to the first value
  197. * in the array returned by <code>getParameterValues</code>.
  198. *
  199. * <p>If the parameter data was sent in the request body, such as occurs
  200. * with an HTTP POST request, then reading the body directly via {@link
  201. * #getInputStream} or {@link #getReader} can interfere
  202. * with the execution of this method.
  203. *
  204. * @param name a <code>String</code> specifying the
  205. * name of the parameter
  206. *
  207. * @return a <code>String</code> representing the
  208. * single value of the parameter
  209. *
  210. * @see #getParameterValues
  211. *
  212. */
  213. public String getParameter(String name);
  214. /**
  215. *
  216. * Returns an <code>Enumeration</code> of <code>String</code>
  217. * objects containing the names of the parameters contained
  218. * in this request. If the request has
  219. * no parameters, the method returns an
  220. * empty <code>Enumeration</code>.
  221. *
  222. * @return an <code>Enumeration</code> of <code>String</code>
  223. * objects, each <code>String</code> containing
  224. * the name of a request parameter; or an
  225. * empty <code>Enumeration</code> if the
  226. * request has no parameters
  227. *
  228. */
  229. public Enumeration getParameterNames();
  230. /**
  231. * Returns an array of <code>String</code> objects containing
  232. * all of the values the given request parameter has, or
  233. * <code>null</code> if the parameter does not exist.
  234. *
  235. * <p>If the parameter has a single value, the array has a length
  236. * of 1.
  237. *
  238. * @param name a <code>String</code> containing the name of
  239. * the parameter whose value is requested
  240. *
  241. * @return an array of <code>String</code> objects
  242. * containing the parameter's values
  243. *
  244. * @see #getParameter
  245. *
  246. */
  247. public String[] getParameterValues(String name);
  248. /** Returns a java.util.Map of the parameters of this request.
  249. * Request parameters
  250. * are extra information sent with the request. For HTTP servlets,
  251. * parameters are contained in the query string or posted form data.
  252. *
  253. * @return an immutable java.util.Map containing parameter names as
  254. * keys and parameter values as map values. The keys in the parameter
  255. * map are of type String. The values in the parameter map are of type
  256. * String array.
  257. *
  258. */
  259. public Map getParameterMap();
  260. /**
  261. * Returns the name and version of the protocol the request uses
  262. * in the form <i>protocol/majorVersion.minorVersion</i>, for
  263. * example, HTTP/1.1. For HTTP servlets, the value
  264. * returned is the same as the value of the CGI variable
  265. * <code>SERVER_PROTOCOL</code>.
  266. *
  267. * @return a <code>String</code> containing the protocol
  268. * name and version number
  269. *
  270. */
  271. public String getProtocol();
  272. /**
  273. * Returns the name of the scheme used to make this request,
  274. * for example,
  275. * <code>http</code>, <code>https</code>, or <code>ftp</code>.
  276. * Different schemes have different rules for constructing URLs,
  277. * as noted in RFC 1738.
  278. *
  279. * @return a <code>String</code> containing the name
  280. * of the scheme used to make this request
  281. *
  282. */
  283. public String getScheme();
  284. /**
  285. * Returns the host name of the server that received the request.
  286. * For HTTP servlets, same as the value of the CGI variable
  287. * <code>SERVER_NAME</code>.
  288. *
  289. * @return a <code>String</code> containing the name
  290. * of the server to which the request was sent
  291. */
  292. public String getServerName();
  293. /**
  294. * Returns the port number on which this request was received.
  295. * For HTTP servlets, same as the value of the CGI variable
  296. * <code>SERVER_PORT</code>.
  297. *
  298. * @return an integer specifying the port number
  299. *
  300. */
  301. public int getServerPort();
  302. /**
  303. * Retrieves the body of the request as character data using
  304. * a <code>BufferedReader</code>. The reader translates the character
  305. * data according to the character encoding used on the body.
  306. * Either this method or {@link #getInputStream} may be called to read the
  307. * body, not both.
  308. *
  309. *
  310. * @return a <code>BufferedReader</code>
  311. * containing the body of the request
  312. *
  313. * @exception UnsupportedEncodingException if the character set encoding
  314. * used is not supported and the
  315. * text cannot be decoded
  316. *
  317. * @exception IllegalStateException if {@link #getInputStream} method
  318. * has been called on this request
  319. *
  320. * @exception IOException if an input or output exception occurred
  321. *
  322. * @see #getInputStream
  323. *
  324. */
  325. public BufferedReader getReader() throws IOException;
  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. public String getRemoteAddr();
  336. /**
  337. * Returns the fully qualified name of the client that sent the
  338. * request. If the engine cannot or chooses not to resolve the hostname
  339. * (to improve performance), this method returns the dotted-string form of
  340. * the IP address. For HTTP servlets, same as the value of the CGI variable
  341. * <code>REMOTE_HOST</code>.
  342. *
  343. * @return a <code>String</code> containing the fully
  344. * qualified name of the client
  345. *
  346. */
  347. public String getRemoteHost();
  348. /**
  349. *
  350. * Stores an attribute in this request.
  351. * Attributes are reset between requests. This method is most
  352. * often used in conjunction with {@link RequestDispatcher}.
  353. *
  354. * <p>Attribute names should follow the same conventions as
  355. * package names. Names beginning with <code>java.*</code>,
  356. * <code>javax.*</code>, and <code>com.sun.*</code>, are
  357. * reserved for use by Sun Microsystems.
  358. *<br> If the value passed in is null, the effect is the same as
  359. * calling {@link #removeAttribute}.
  360. *
  361. *
  362. *
  363. * @param name a <code>String</code> specifying
  364. * the name of the attribute
  365. *
  366. * @param o the <code>Object</code> to be stored
  367. *
  368. */
  369. public void setAttribute(String name, Object o);
  370. /**
  371. *
  372. * Removes an attribute from this request. This method is not
  373. * generally needed as attributes only persist as long as the request
  374. * is being handled.
  375. *
  376. * <p>Attribute names should follow the same conventions as
  377. * package names. Names beginning with <code>java.*</code>,
  378. * <code>javax.*</code>, and <code>com.sun.*</code>, are
  379. * reserved for use by Sun Microsystems.
  380. *
  381. *
  382. * @param name a <code>String</code> specifying
  383. * the name of the attribute to remove
  384. *
  385. */
  386. public void removeAttribute(String name);
  387. /**
  388. *
  389. * Returns the preferred <code>Locale</code> that the client will
  390. * accept content in, based on the Accept-Language header.
  391. * If the client request doesn't provide an Accept-Language header,
  392. * this method returns the default locale for the server.
  393. *
  394. *
  395. * @return the preferred <code>Locale</code> for the client
  396. *
  397. */
  398. public Locale getLocale();
  399. /**
  400. *
  401. * Returns an <code>Enumeration</code> of <code>Locale</code> objects
  402. * indicating, in decreasing order starting with the preferred locale, the
  403. * locales that are acceptable to the client based on the Accept-Language
  404. * header.
  405. * If the client request doesn't provide an Accept-Language header,
  406. * this method returns an <code>Enumeration</code> containing one
  407. * <code>Locale</code>, the default locale for the server.
  408. *
  409. *
  410. * @return an <code>Enumeration</code> of preferred
  411. * <code>Locale</code> objects for the client
  412. *
  413. */
  414. public Enumeration getLocales();
  415. /**
  416. *
  417. * Returns a boolean indicating whether this request was made using a
  418. * secure channel, such as HTTPS.
  419. *
  420. *
  421. * @return a boolean indicating if the request was made using a
  422. * secure channel
  423. *
  424. */
  425. public boolean isSecure();
  426. /**
  427. *
  428. * Returns a {@link RequestDispatcher} object that acts as a wrapper for
  429. * the resource located at the given path.
  430. * A <code>RequestDispatcher</code> object can be used to forward
  431. * a request to the resource or to include the resource in a response.
  432. * The resource can be dynamic or static.
  433. *
  434. * <p>The pathname specified may be relative, although it cannot extend
  435. * outside the current servlet context. If the path begins with
  436. * a "/" it is interpreted as relative to the current context root.
  437. * This method returns <code>null</code> if the servlet container
  438. * cannot return a <code>RequestDispatcher</code>.
  439. *
  440. * <p>The difference between this method and {@link
  441. * ServletContext#getRequestDispatcher} is that this method can take a
  442. * relative path.
  443. *
  444. * @param path a <code>String</code> specifying the pathname
  445. * to the resource
  446. *
  447. * @return a <code>RequestDispatcher</code> object
  448. * that acts as a wrapper for the resource
  449. * at the specified path
  450. *
  451. * @see RequestDispatcher
  452. * @see ServletContext#getRequestDispatcher
  453. *
  454. */
  455. public RequestDispatcher getRequestDispatcher(String path);
  456. /**
  457. *
  458. * @deprecated As of Version 2.1 of the Java Servlet API,
  459. * use {@link ServletContext#getRealPath} instead.
  460. *
  461. */
  462. public String getRealPath(String path);
  463. }