String env throws java. UnsupportedEncodingException Overrides the name of the character encoding used in the body of this request. This method must be called prior to reading request parameters or reading input using getReader. Otherwise, it has no effect.
Parameters: env - String containing the name of the character encoding. Throws: java. UnsupportedEncodingException - if this ServletRequest is still in a state where a character encoding may be set, but the specified encoding is invalid getContentLength int getContentLength Returns the length, in bytes, of the request body and made available by the input stream, or -1 if the length is not known.
Returns: an integer containing the length of the request body or -1 if the length is not known getContentType java. Either this method or getReader may be called to read the body, not both. Returns: a ServletInputStream object containing the body of the request Throws: IllegalStateException - if the getReader method has already been called for this request java.
IOException - if an input or output exception occurred getParameter java. Request parameters are extra information sent with the request. For HTTP servlets, parameters are contained in the query string or posted form data. You should only use this method when you are sure the parameter has only one value.
If the parameter might have more than one value, use getParameterValues java. If you use this method with a multivalued parameter, the value returned is equal to the first value in the array returned by getParameterValues. If the parameter data was sent in the request body, such as occurs with an HTTP POST request, then reading the body directly via getInputStream or getReader can interfere with the execution of this method.
Parameters: name - a String specifying the name of the parameter Returns: a String representing the single value of the parameter See Also: getParameterValues java. String getParameterNames java.
If the request has no parameters, the method returns an empty Enumeration. Returns: an Enumeration of String objects, each String containing the name of a request parameter; or an empty Enumeration if the request has no parameters getParameterValues java.
If the parameter has a single value, the array has a length of 1. Parameters: name - a String containing the name of the parameter whose value is requested Returns: an array of String objects containing the parameter's values See Also: getParameter java.
String getParameterMap java. Returns: an immutable java. Map containing parameter names as keys and parameter values as map values. The keys in the parameter map are of type String. The values in the parameter map are of type String array. Returns: a String containing the protocol name and version number getScheme java.
Returns: a String containing the name of the scheme used to make this request getServerName java. It is the value of the part before ":" in the Host header value, if any, or the resolved server name, or the server IP address. Returns: a String containing the name of the server getServerPort int getServerPort Returns the port number to which the request was sent.
It is the value of the part after ":" in the Host header value, if any, or the server port where the client connection was accepted on. Returns: an integer specifying the port number getReader java. BufferedReader getReader throws java. The reader translates the character data according to the character encoding used on the body.
Either this method or getInputStream may be called to read the body, not both. Returns: a BufferedReader containing the body of the request Throws: java. UnsupportedEncodingException - if the character set encoding used is not supported and the text cannot be decoded IllegalStateException - if getInputStream method has been called on this request java.
If the engine cannot or chooses not to resolve the hostname to improve performance , this method returns the dotted-string form of the IP address. Returns: a String containing the fully qualified name of the client setAttribute void setAttribute java. Attributes are reset between requests. This method is most often used in conjunction with RequestDispatcher. Names beginning with java.
If the object passed in is null, the effect is the same as calling removeAttribute java. It is warned that when the request is dispatched from the servlet resides in a different web application by RequestDispatcher , the object set by this method may not be correctly retrieved in the caller servlet. Parameters: name - a String specifying the name of the attribute o - the Object to be stored removeAttribute void removeAttribute java.
This method is not generally needed as attributes only persist as long as the request is being handled. Parameters: name - a String specifying the name of the attribute to remove getLocale java. If the client request doesn't provide an Accept-Language header, this method returns the default locale for the server. Returns: the preferred Locale for the client getLocales java. If the client request doesn't provide an Accept-Language header, this method returns an Enumeration containing one Locale , the default locale for the server.
Returns: an Enumeration of preferred Locale objects for the client isSecure boolean isSecure Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS. Returns: a boolean indicating if the request was made using a secure channel getRequestDispatcher RequestDispatcher getRequestDispatcher java. A RequestDispatcher object can be used to forward a request to the resource or to include the resource in a response.
The resource can be dynamic or static. The pathname specified may be relative, although it cannot extend outside the current servlet context.
This method returns null if the servlet container cannot return a RequestDispatcher. The difference between this method and ServletContext getRequestDispatcher is that this method can take a relative path. Parameters: path - a String specifying the pathname to the resource. If it is relative, it must be relative against the current servlet.
Returns: an integer specifying the port number Since: Servlet 2. Returns: a String containing the host name of the IP on which the request was received. Since: Servlet 2. Returns: a String containing the IP address on which the request was received. Now I just create a Dynamic Web Project, then add a server usually Tomcat , then right click on the new project - select properties - select project facets and add the Tomcat Server as the runtime.
It has the files you need. Once you hit the apply button and okay button it will resolve the missing import files. Here is a step by step description from a similar question on SO: How do I import the javax. You'll want to add the Servlet API as a "provided" dependency. That is, you only use it to compile the code, but you don't need to package it with your web application since your web container will already contain a copy of it. Stack Overflow for Teams — Collaborate and share knowledge with a private group.
Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Need the JAR file for a javax. HttpServletRequest [duplicate] Ask Question. Asked 7 years, 4 months ago. Active 5 years, 3 months ago.
Viewed 65k times. Moon Moon You need the servlet api. It is generally provided by your servlet container. You could, but no. Your websphere installation will have the servlet-api somewhere.
Otherwise, you can get it here. SotiriosDelimanolis which version 3. You can include Tomcat dependencies in Maven via the tomcat-servlet-api and tomcat-jsp-api jars. One exists for each version of Tomcat. Usually adding these with scope provided is sufficient.
0コメント