Java Servlet API Description Document (2.1A) (3)

xiaoxiao2021-03-06  59

Java Servlet API Description Document (2.1A) (3)

Summary

Continued Java Servlet API Description Document (2.1A) (2) (2002-08-29 13:28:11)

By Wing, Source:

LinuxAid

Package: Javax.Servlet.http includes interface: httpservletRequest; httpsession; httpsessionBindingListener; httpsessionContext. The class contained: cookie; httpservlet; httpsessionBindingEvent; httputils. First, HTTPSERVLETREQUEST interface definition

Public interface httpservletRequest Extends ServletRequest; request information for processing a HTTP format for servlet. Method 1, GetAuthtype

Public string getAuthtype (); return to this request authentication mode. 2, GetCookies

Public cookie [] getCookies (); returns an array that contains all current cookies in this request. If there is no cookie in this request, an empty array is returned.

3, getDateHeader public long getdateHeader (String name); Returns the value of the specified request header field, which is converted into a long integer that reflects the accurate to milliseconds since 1970-1-1 (GMT). If the head domain cannot be converted, an IllegaLargumentException is thrown. This method returns -1 if this request header is not exist. 4, GetHeader

Public String GetHeader (String Name); returns a value of a request header. (Translator Note: Different from the previous method, this method returns a string) If this request header is not existed, this method returns -1. 5, GetHeadernames

Public Enumeration getHeadernAmes (); This method returns a list of String objects that reflect all header names of the request. Some engines may not allow access to the header in this way. In this case, this method returns an empty list. 6, GetInTheader

Public int getInetre (String name); Returns the value of the specified request header field, this value is converted into an integer. If the head domain cannot be converted, an IllegaLargumentException is thrown. This method returns -1 if this request header is not exist. 7, getMethod

Public string getMethod (); Returns the HTTP method used by this request (for example: get, post, put) 8, getPathInfo

Public String getPathInfo (); This method returns an additional path information of the request URL after the servlet path of the requesting URL. If this request URL includes a query string, this query string will not be included in the return value. This path must be decoded by URL before returning. If there is no path information after the servlet path of this requested URL. This method returns null value. 9, getPathtranslated

Public String getPathTranslated (); This method gets additional path information after the servlet path of this request, and converts it into a real path. The requested URL must be decoded by the URL before conversion. If there is no additional path information after the servlet path of this URL. This method returns null value. 10, getQueryStringPublic string getQueryString (); Returns the query string included in this request URL. A query string is taken out in a URL. If you do not query strings, this method returns null value. 11, GetRemoteuser

Public String GetRemoteUser returns a request for username, this information is used to make HTTP user arguments. If there is no username message in the request, this method returns a null value. 12, getRequestedSessionIDID

Public String getRequestedSessionID (); Returns this request corresponding session ID. If the Session ID provided by a reason client is invalid, this session ID will be different from the Session ID in the current session, and will create a new session. If this request is not associated with a session, this method returns a null value. 13, GetRequesturi

Public String getRequesturi (); the part of the requested resource is defined in the requested URL returns from the first row of the HTTP request. If there is a query string exists, this query string will not be included in the return value. For example, a request to access the URL path to the / catalog / books? Id = 1, this method will return / catalog / books. The return value of this method includes servlet path and path information. If a part of this URL path passes URL encoding, the return value of this method must be decoded before returning. 14, GetServletPath

Public string getServletPath (); This method returns the request URL reflects the part of the calling servlet. For example, a servlet is mapped to the / catalog / summer this URL path, and a request uses the path to / catalog / summer / casal. The so-called part of the calling servlet refers to / catalog / summer. If this servlet is called by a path match. This method will return an empty value. 15, GetSession

Public httpsession getsession ();

Public httpsession getsession (Boolean Create);

Returns the current valid session associated with this request. If you don't have a parameter when calling this method, then a session will be created without the SESSION with this request. If this method is called, a Boolean parameter is brought, and the session will only be established when this parameter is true. To ensure that session can be fully maintained. The servlet developer must call the method before the response is submitted. If the parameters belled are false, and there is no session associated with this request. This method returns null value. 16, IsRequestedSessionIndiDValid

Public Boolean isRequestedSessionIDValid (); This method checks that the session associated with this request is currently valid. If the session used in the current request is invalid, it will not return to the getSession method. 17, IsRequestedSessionIDFromCookie

Public Boolean isRequestedSessionIDFromCookie (); if this request is provided through a cookie of the client, the method returns true, otherwise it returns false. 18, isRequestedSessionIDFromurlPublic Boolean isRequestedSessionIDFromurl (); if this request is provided through a part of the client's URL, the method returns true, otherwise it returns false. Note that this method is different from IsRequestedSessionIDFromurl spelling in the URL. The following methods will be canceled 19, isRequestedSessionIDFromurl

Public Boolean isRequestedSessionIDFromurl (); this method is replaced by IsRequestedSessionIDFromurl. Second, HTTPSERVLETRESPONSE interface definition

Public Interface HttpServletResponse Extends ServletResponse describes a HTTP response that is returned to the client. This interface allows the servlet programmers to utilize the header information specified by the HTTP protocol. Member variables

Public static final int sc_continue = 100;

Public Static Final Int Sc_Switching_Protocols = 101;

Public static final int sc_ok = 200;

Public static final int sc_created = 201;

Public static final int sc_accepted = 202;

Public Static Final Int SC_NON_AUTHORITATIVE_INFORMATION = 203;

Public static final int sc_no_content = 204;

Public Static Final Int SC_RESET_CONTENT = 205;

Public Static Final Int SC_PARTIAL_CONTENT = 206;

Public Static Final Int SC_MULTIPLE_CHOICES = 300;

Public static final int sc_moved_persManently = 301;

Public static final int sc_moved_temporarily = 302;

Public Static Final Int sc_see_other = 303;

Public Static Final Int SC_NOT_MODIFIED = 304;

Public static final int sc_Use_proxy = 305;

Public static final int sc_bad_request = 400;

Public static final int sc_unauthorized = 401;

Public static final int sc_payment_required = 402;

Public static final int sc_forbidden = 403;

Public static final INT sc_not_found = 404;

Public Static Final Int SC_METHOD_NOT_ALLOWED = 405;

Public static final int sc_not_acceptable = 406;

Public static final int sc_proxy_authentication_required = 407; public static final INT sc_request_timeout = 408;

Public static final int sc_conflict = 409;

Public Static Final Int SC_GONE = 410;

Public Static Final Int SC_LENGTH_REQUIRED = 411;

Public Static Final Int SC_PRECondition_failed = 412;

PUBLIC Static Final Int SC_REQUEST_ENTINTITY_TOO_LARGE = 413;

Public static final int sc_request_uri_too_long = 414;

Public Static Final Int SC_UNUNSUNSUPPORTED_MEDIA_TYPE = 415;

Public static final int sc_internal_server_error = 500;

Public Static Final Int SC_NOT_IMPLEMENTED = 501;

Public static final INT sc_bad_gateway = 502;

Public Static Final Int SC_Service_unavailable = 503;

Public static final int sc_gateway_timeout = 504;

Public static final int sc_http_version_not_supported = 505;

The above HTTP production status code is defined by http / 1.1. Method 1, AddCookie

Public void addCookie (cookie cookie) adds a specified cookie in the response. This method can be called multiple times to define multiple cookies. In order to set the appropriate head domain, the method should be called before the response is submitted. 2, Containsheader

Public Boolean ContainSheader (String Name); Check if the specified response header is set. 3, EncoderedirectURL

Public String EncodeRedirectURL (String URL); encodes the specified URL used by the SendRedirect method. If you do not need to be encoded, you will return this URL directly. This additional coding method is provided because the rules that decide whether to encode the URL in the case of Redirect. The URL given must be an absolute URL. Relative URLs cannot be received, an IllegaLargumentException will be thrown. All URLs that provide to the SendRedirect method should run through this method, so that session tracking can run normally in all browsers. 4, EncodeURL

Public String EncodeURL (String URL); encodes a URL containing the session ID. If you do not need to be encoded, you will return this URL directly. The servlet engine must provide a URL encoding method, because in some cases, we will have to rewrite the URL, for example, in response to the corresponding request containing a valid session, but this session cannot be non-URL (such as cookie) means To maintain. All URLs provided to servlet should run through this method, so that session tracking can run normally in all browsers. 5, SenderrorPublic void senderror (int statuscode) throws oewception;

Public Void Senderror (int Statuscode, String Message) Throws

IOEXCEPTION;

Send an error response to the client with a given status code. If a Message parameter is provided, this will be issued as part of the responsive body, otherwise, the server returns the standard information corresponding to the error code. After calling this method, the response is immediately submitted. After calling this method, servlet will no longer have more output. 6, Sendredirect

Public void sendredirect (string location) THROWS IOException; uses a given path to issue a temporary steering response (SC_MOVED_TEMPORARILY). A given path must be an absolute URL. The relative URL will not be received and an IllegaLargumentException will be thrown. This method must be called before the response is submitted. After calling this method, the response is immediately submitted. After calling this method, servlet will no longer have more output. 7, SetDateHeader

Public void setdateHeader (String Name, long Date); setting the response head with a given name and date value, the date value here should be reflected in the exact intensity of the 1970-1-1 days (GMT). If the response head has been set, the new value will overwrite the current value. 8, SetHeader

Public void setHeader (String name, string value); set the response head with a given name and domain. If the response head has been set, the new value will overwrite the current value. 9, setIntheader

Public void setInTheader (String name, int value); sets the response header with a given name and shaping value. If the response head has been set, the new value will overwrite the current value. 10, SetStatus

Public void setStatus; This method sets the status code of the response. If the status code has been set, the new value will overwrite the current value. Several methods will be canceled 11, EncoderedirectURL

Public String EncodeRedirectURL (String URL); This method is replaced by EncoderedirectURL. 12, EncodeURL

Public String EncodeURL (String URL); This method is replaced by EncodeURL. 13, SetStatus

Public void setStatus (int status, String message); This method sets the status code of the response, and if the status code has been set, the new value will overwrite the current value. If a message is provided, it will also be sent as part of the responsive body. Third, the httpsession interface definition public interface httpsession This interface is used by the Servlet engine to achieve both the HTTP client and the HTTP session. This association may continue a given time in multiple external connections and requests. Session is used to maintain status and identify users under the stateless HTTP protocol. A session can be maintained by cookie or rewriting the URL. Method 1, GetCreationTime

Public long getCreationTime (); Returns the time of establishing the session, this time is represented by milliseconds since 1970-1-1 (GMT). 2, GetID

Public string getId (); returns an identifier assigned to this session. An Identifier of an HTTP Session is a unique string that is established and maintained by the server. 3, getlastaccessedtime

Public long getlastaccessedTime (); Return to the client to issue the time related to this session, if this session is new, return -1. This time is expressed as a millisecond since 1970-1-1 (GMT). 4, getMaxinactiveInterval

Public int getMaxinactiveInterval (); returns a second number, this second indicates that the client maintains the longest period of the Servlet engine when the client does not issue a request. After this time, the servlet engine may be terminated by the servlet engine. If this session is not terminated, this method returns -1. When the session is invalid, call this method to throw an ILLEGALSTATEEXCEPTION. 5, GetValue

Public Object getValue (String Name); Returns an object that binds to the session at a given name. If there is no such binding, return null values. When the session is invalid, call this method to throw an ILLEGALSTATEEXCEPTION. 6, getValuenames

Public string [] getValuenames (); Returns the name of all data binding to the session with an array. When the session is invalid, call this method to throw an ILLEGALSTATEEXCEPTION. 7, Invalidate

Public void invalidate (); this method will terminate this session. All bindings on this session will be cleared. And make an announcement through the valueunbound method of the HTTPSESSSIONBINDINGLISTENER interface. 8, isnew

Public Boolean isnew (); Returns a Boolean value to determine that this session is new. If a session has been established by the server but has not received the corresponding client request, this session will be considered new. This means that this client has not joined a session or is not recognized by sessions. You can't return the appropriate session authentication information when he issued the next request. When the session is invalid, call this method to throw an ILLEGALSTATEEXCEPTION. 9, PUTVALUE

Public void PutValue (String Name, Object Value); Binds a given object to the session at a given name. The binding of the existing same name will be reset. At this time, the valuebound method of the HTTPSessionBindingListener interface is called. When the session is invalid, call this method to throw an ILLEGALSTATEEXCEPTION. 10, RemoveValuePublic Void RemoveValue (String Name); Cancel the object of the given name in the SESSION. This method does not do if the object of the binding of a given name is not found. The valueunbound method for the HttpSessionBindingListener interface is called. When the session is invalid, call this method to throw an ILLEGALSTATEEXCEPTION. 11, SetMaxINactiveInterval

Public int setMaxinactiveInterval (int interface); Sets a second number indicating that the client maintains the longest time that the client will maintain by the servlet engine when the client is not issued. The following methods will be canceled 12, getsessionContext

Public httpsessionContext GetSessionContext (); Returns the environment variables whose session is maintained. This method is canceled like all other httpsessionContext methods. Fourth, httpsessionBindingListener interface definition

Public interface httpsessionBindingListener This object is added to the HTTP session, and the execution of this interface will notify any object being bound to this http session or cancel the bind from this HTTP Session. Method 1, ValueBound

Public void valueBound (httpsessionBindingEvent Event); This method is called when an object is bound to the session. When the HttpSession.putValue method is called, the servlet engine should call this method. 2, Valueunbound

Public void valueunbound (httpsessionBindingEvent Event); This method is called when an object is unbinded from the Session. When the HttpSession.RemoveValue method is called, the Servlet engine should call this method. 5. HTTPSESSIONCONTEXT interface defines this interface will be canceled

Public interface httpsessionContext This object is a single entity associated with a group of HTTP session. This interface is canceled due to safety, and it appears in the current version only for compatibility. The method of this interface returns the corresponding value to the definition of the previous version. Method 1, GetSession

Public httpsession getsession (String sessionid); used to return Session related to this session ID. Now return null values. 2, GetIDS

Public Enumeration GetIDS (); the list used to return to all session IDs in this environment. Now return a list of empty. 6. Cookie class definition

Public Class Cookie Implements Cloneable This class describes a cookie, and you can refer to RFC 2109 with reference to Netscape Communications Corporation. Constructor

Public cookie (String name, string value); define a cookie with a name-value. This Name must be accepted by HTTP / 1.1. Name starting with character $ is retained by RFC 2109. A given Name If it cannot be accepted by HTTP / 1.1, this method throws an ILLEGALARGUMENTEXCEPTION. Method 1, getcommentpublic string getcomment (); returns a description describing this cookie purpose, if this instruction is not defined, return null values. 2, GetDomain

Public string getdomain (); Returns the area where this cookie can appear, if the area is not defined, return null values. 3, getMaxage

Public int getMaxage (); this method returns the longest survival period specified by this cookie. This method returns -1 if this maximum survival period is not defined. 4, getname

Public string getName (); This method returns a cookie name. 5, getpath

Public string getPath (); Returns this cookie's prefix that is valid for all URL paths, if not defined, return null values. 6, GetSecure

Public Boolean getsecure (); if this cookie returns only through the secure channel transfer, otherwise return false. 7, GetValue

Public string getValue (); This method returns the value of the cookie.

8, getversion public int getversion (); Returns the version of the cookie. Version 1 is explained by RFC 2109. Version 0 Explanation by Netscape Communications Corporation. New construction cookie defaults to use version 0. 9, setcomment

Public void setcomment; if a user submits this cookie to another user, you must describe this cookie's purpose through this instruction. Version 0 does not support this property. 10, setdomain

Public void setdomain (String Pattern); This method sets the properties of the cookie's valid domain. This property specifies the area where cookie can appear. A valid domain begins with a point (.foo.com), which means that this cookie can be seen in the area of ​​the specified domain analysis system (probably www.foo.com but not a.foo.com). By default, cookies can only return to save its host. 11, SetMaxage

Public void setMaxage (int expiry); This method sets the longest survival of this cookie. After this survival period, cookies will be deadly. Negative numbers indicate that this cookie does not take effect, 0 will delete this cookie from the client. 12, setpath

Public void setPath; This method sets the path properties of the cookie. The client can only return cookies to the path starting with this given path string. 13, SetSecure

Public void setsecure (Boolean Flag); pointing this cookie can only be sent through a secure channel (eg HTTPS). This will only be set when the Cookie value is sent using a security protocol to send this cookie value using a security protocol. 14, SetValue

Public void setValue; Sets the value of this cookie, using Base64 encoding for binary data. Version 0 cannot use spaces, {}, (), = ,,, "", /,?, @ ,: and; 15, setVersionPublic void setversion (int V); set the version number of the cookie, HTTPSERVLET class definition

Public class httpservlet Extends GenericServlet Implements

Serializable

This is an abstract class that simplifies the process of HTTP servlet writing. It is an expansion of the GenericServlet class, providing a framework for processing HTTP protocols. The service method in this class supports, for example, standard HTTP methods such as GET, POST. This support process is implemented by assigning them to an appropriate approach (such as DOGET, DOPOST). Method 1, Dodelete

Protected Void Dodelete (HttpservletRequest Request,

HttpservletResponse response) Throws servletexception,

IOEXCEPTION;

Call is called by this class to process an HTTP DELETE operation. This operation allows client requests to delete URLs from the server. This operation may have a negative impact, and it is responsible for this user. The default execution result of this method is to return an HTTP BAD_REQUEST error. You must overload this method when you want to deal with Delete requests. 2, doget

Protected Void Doget (httpservletRequest Request,

HttpservletResponse response) Throws servletexception,

IOEXCEPTION;

The service method of this class is called to process an HTTP GET operation. This operation allows clients to simply "get" resources from an HTTP server. The overloading of this method will automatically support the HEAD method. GET operations should be safe and there is no negative impact. This operation should also be safely repeated safely. The default execution result of this method is to return an HTTP BAD_REQUEST error. 3, dohead

Protected void dohead (httpservletRequest Request,

HttpservletResponse response) Throws servletexception,

IOEXCEPTION;

The service method of this class is called to process an HTTP HEAD operation. The default case is that this operation will be performed in accordance with an unconditional GET method, which does not return any data to the client, but only returns header information that contains the length of the content. Like the GET operation, this operation should be safe and there is no negative impact. This operation should also be safely repeated safely. The default execution result of this method is to automatically handle the HTTP HEAD operation, which does not need to be performed by one subclass. 4, doOptions

Protected void dooptions (httpservletRequest Request,

HttpservletResponse response) Throws servletexception,

IOEXCEPTION;

Call is called by this class to process an HTTP Option operation. This operation automatically decides which HTTP method to support. For example, a servlet writes a subclass of httpservlets and overloads the Doget method, and DoOption will return to the head below: Allow: Get, Head, Trace, Options You generally do not need to overload this method. 5, dopostprotected void dopost (httpservletRequest Request,

HttpservletResponse response) Throws servletexception,

IOEXCEPTION;

The service method of this class is called to process an HTTP POST operation. This operation contains the data of the requester, and servlet should follow him. This action may have a negative impact. For example, update storage data or online shopping. The default execution result of this method is to return an HTTP BAD_REQUEST error. When you want to handle the POST operation, you must overload this method in the subclass of the HTTPSERVLET. 6, DOPUT

Protected Void Doput (HttpServletRequest Request,

HttpservletResponse response) Throws servletexception,

IOEXCEPTION;

Call is called by this class to process an HTTP PUT operation. This operation is similar to sending files via FTP. This action may have a negative impact. For example, update storage data or online shopping. The default execution result of this method is to return an HTTP BAD_REQUEST error. When you want to handle the PUT operation, you must overload this method in the subclass of the HTTPSERVLET. 7, Dotrace

Protected Void Dotrace (httpservletRequest Request,

HttpservletResponse response) Throws servletexception,

IOEXCEPTION;

Call is called by this class to process an HTTP TRACE operation. The default execution result of this operation is to generate a response, which contains information that reflects all headers sent in the Trace request. When you develop servlets, in most cases you need to overload this method. 8, getlastmodified

protected long getlastmodified (httpservletRequest request); returns the last modification time of this request entity. To support GET operations, you must overload this method to accurately reflect the last modified time. This will help the browser and proxy servers to reduce loading servers and network resources, making more efficient work. The number of returned is the number of milliseconds since 1970-1-1-1 (GMT). The default execution result is returns a negative number, which marks the final modification time unknown, it cannot be used by a conditional GET operation. 9, Service

Protected Void Service (httpservletRequest Request,

HttpservletResponse response) Throws servletexception,

IOEXCEPTION;

Public void service (servletRequest Request, ServletResponse Response)

Throws servletexception, ioException;

This is a servlet's HTTP-SPECIFIC solution that assigns other methods for supporting this request to support this class. When you develop servlets, in most cases you don't have to overload this method. 8. HTTPSESSIONBINDINGEVENT Class definition public class httpsessionBindingEvent Extends eventObject This event is incorporated in HttpSessionBindingListener when listening to the httpsession binding and cancel binding. This may be a result of session being terminated or identified. The event source is httpsession.putValue or httpsession.removevalue. Constructor

Public httpsessionBindingEvent (httpsession session, string name); constructs a new HttpSessionBindInGevent by causing Session of this event and a binding or unbound object name. Method 1, GetName

Public string getName (); returns the name of the object that occurs and cancels the bound. 2, GetSession

Public httpsession getsession (); returns the name of the Session that occurs and unsubstituted. Nine, httputils definition

Public class httputils collects the static effective ways for HTTP Servlet. Method 1, GetRequestURL

Public Static StringBuffer GetRequestURL (httpservletRequest

REQUEST;

Reconstruct the client on the server to establish the URL of the request. This method reflects different protocols (eg HTTP and HTTPS) and ports, but does not include query strings. This method returns a StringBuffer instead of a string so that the URL can be effectively modified by the servlet developer. 2, ParsepostData

Public Static Hashtable ParsepostData (Int Len,

ServletInputStream in);

Parked a stream of data that contains MIME type Application / X-WWW-FORM-URLENCODED and creates a Hash Table with a key value-data pair. The key value here is a string, and the data is a list of values ​​corresponding to the string. A key value can appear once or more in POST data. Each time this key value occurs once, its corresponding value is added to the list of values ​​corresponding to the string in the Hash Table. The data read from the POST data will pass through the URL decoding, will be converted to a space to be transmitted by hexadecimal (eg,% xx) will be converted into characters. This method throws an ILLEGALARGUMENTEXCEPTION when POST data is invalid. 3, ParseQueryString

Public Static HashTable ParseQueryString (String S); parsing a query string and creates a key Table with a key value-data pair. The data here is a list of values ​​corresponding to the string. A key value can appear once or more. Each time this key value occurs once, its corresponding value is added to the list of values ​​corresponding to the string in the Hash Table. The data read from the query string will pass through the URL decoding, and will be converted to the space transmitted by hexadecimal (eg,% xx) will be converted into characters. This method throws an ILLEGALARGUMENTEXCEPTION when the query string is invalid.

转载请注明原文地址:https://www.9cbs.com/read-112683.html

New Post(0)